]> git.sesse.net Git - ffmpeg/blob - compat/avisynth/avisynth_c.h
Merge commit 'eb8a8115994434b548523cf0bca6a4a74784e79c'
[ffmpeg] / compat / avisynth / avisynth_c.h
1 // Avisynth C Interface Version 0.20
2 // Copyright 2003 Kevin Atkinson
3
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.
8 //
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.
13 //
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., 51 Franklin Street, Fifth Floor, Boston,
17 // MA 02110-1301 USA, or visit
18 // http://www.gnu.org/copyleft/gpl.html .
19 //
20 // As a special exception, I give you permission to link to the
21 // Avisynth C interface with independent modules that communicate with
22 // the Avisynth C interface solely through the interfaces defined in
23 // avisynth_c.h, regardless of the license terms of these independent
24 // modules, and to copy and distribute the resulting combined work
25 // under terms of your choice, provided that every copy of the
26 // combined work is accompanied by a complete copy of the source code
27 // of the Avisynth C interface and Avisynth itself (with the version
28 // used to produce the combined work), being distributed under the
29 // terms of the GNU General Public License plus this exception.  An
30 // independent module is a module which is not derived from or based
31 // on Avisynth C Interface, such as 3rd-party filters, import and
32 // export plugins, or graphical user interfaces.
33
34 // NOTE: this is a partial update of the Avisynth C interface to recognize
35 // new color spaces added in Avisynth 2.60. By no means is this document
36 // completely Avisynth 2.60 compliant.
37
38 #ifndef __AVISYNTH_C__
39 #define __AVISYNTH_C__
40
41 #include "avs/config.h"
42 #include "avs/capi.h"
43 #include "avs/types.h"
44
45
46 /////////////////////////////////////////////////////////////////////
47 //
48 // Constants
49 //
50
51 #ifndef __AVISYNTH_6_H__
52 enum { AVISYNTH_INTERFACE_VERSION = 6 };
53 #endif
54
55 enum {AVS_SAMPLE_INT8  = 1<<0,
56       AVS_SAMPLE_INT16 = 1<<1,
57       AVS_SAMPLE_INT24 = 1<<2,
58       AVS_SAMPLE_INT32 = 1<<3,
59       AVS_SAMPLE_FLOAT = 1<<4};
60
61 enum {AVS_PLANAR_Y=1<<0,
62       AVS_PLANAR_U=1<<1,
63       AVS_PLANAR_V=1<<2,
64       AVS_PLANAR_ALIGNED=1<<3,
65       AVS_PLANAR_Y_ALIGNED=AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
66       AVS_PLANAR_U_ALIGNED=AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
67       AVS_PLANAR_V_ALIGNED=AVS_PLANAR_V|AVS_PLANAR_ALIGNED,
68       AVS_PLANAR_A=1<<4,
69       AVS_PLANAR_R=1<<5,
70       AVS_PLANAR_G=1<<6,
71       AVS_PLANAR_B=1<<7,
72       AVS_PLANAR_A_ALIGNED=AVS_PLANAR_A|AVS_PLANAR_ALIGNED,
73       AVS_PLANAR_R_ALIGNED=AVS_PLANAR_R|AVS_PLANAR_ALIGNED,
74       AVS_PLANAR_G_ALIGNED=AVS_PLANAR_G|AVS_PLANAR_ALIGNED,
75       AVS_PLANAR_B_ALIGNED=AVS_PLANAR_B|AVS_PLANAR_ALIGNED};
76
77   // Colorspace properties.
78 enum {
79     AVS_CS_YUVA = 1 << 27,
80     AVS_CS_BGR = 1 << 28,
81     AVS_CS_YUV = 1 << 29,
82     AVS_CS_INTERLEAVED = 1 << 30,
83     AVS_CS_PLANAR = 1 << 31,
84
85     AVS_CS_SHIFT_SUB_WIDTH = 0,
86     AVS_CS_SHIFT_SUB_HEIGHT = 8,
87     AVS_CS_SHIFT_SAMPLE_BITS = 16,
88
89     AVS_CS_SUB_WIDTH_MASK = 7 << AVS_CS_SHIFT_SUB_WIDTH,
90     AVS_CS_SUB_WIDTH_1 = 3 << AVS_CS_SHIFT_SUB_WIDTH, // YV24
91     AVS_CS_SUB_WIDTH_2 = 0 << AVS_CS_SHIFT_SUB_WIDTH, // YV12, I420, YV16
92     AVS_CS_SUB_WIDTH_4 = 1 << AVS_CS_SHIFT_SUB_WIDTH, // YUV9, YV411
93
94     AVS_CS_VPLANEFIRST = 1 << 3, // YV12, YV16, YV24, YV411, YUV9
95     AVS_CS_UPLANEFIRST = 1 << 4, // I420
96
97     AVS_CS_SUB_HEIGHT_MASK = 7 << AVS_CS_SHIFT_SUB_HEIGHT,
98     AVS_CS_SUB_HEIGHT_1 = 3 << AVS_CS_SHIFT_SUB_HEIGHT, // YV16, YV24, YV411
99     AVS_CS_SUB_HEIGHT_2 = 0 << AVS_CS_SHIFT_SUB_HEIGHT, // YV12, I420
100     AVS_CS_SUB_HEIGHT_4 = 1 << AVS_CS_SHIFT_SUB_HEIGHT, // YUV9
101
102     AVS_CS_SAMPLE_BITS_MASK = 7 << AVS_CS_SHIFT_SAMPLE_BITS,
103     AVS_CS_SAMPLE_BITS_8 = 0 << AVS_CS_SHIFT_SAMPLE_BITS,
104     AVS_CS_SAMPLE_BITS_10 = 5 << AVS_CS_SHIFT_SAMPLE_BITS,
105     AVS_CS_SAMPLE_BITS_12 = 6 << AVS_CS_SHIFT_SAMPLE_BITS,
106     AVS_CS_SAMPLE_BITS_14 = 7 << AVS_CS_SHIFT_SAMPLE_BITS,
107     AVS_CS_SAMPLE_BITS_16 = 1 << AVS_CS_SHIFT_SAMPLE_BITS,
108     AVS_CS_SAMPLE_BITS_32 = 2 << AVS_CS_SHIFT_SAMPLE_BITS,
109
110     AVS_CS_PLANAR_MASK = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV | AVS_CS_BGR | AVS_CS_YUVA | AVS_CS_SAMPLE_BITS_MASK | AVS_CS_SUB_HEIGHT_MASK | AVS_CS_SUB_WIDTH_MASK,
111     AVS_CS_PLANAR_FILTER = ~(AVS_CS_VPLANEFIRST | AVS_CS_UPLANEFIRST),
112
113     AVS_CS_RGB_TYPE  = 1 << 0,
114     AVS_CS_RGBA_TYPE = 1 << 1,
115
116     AVS_CS_GENERIC_YUV420  = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2,  // 4:2:0 planar
117     AVS_CS_GENERIC_YUV422  = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_2,  // 4:2:2 planar
118     AVS_CS_GENERIC_YUV444  = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_1,  // 4:4:4 planar
119     AVS_CS_GENERIC_Y       = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV,                                             // Y only (4:0:0)
120     AVS_CS_GENERIC_RGBP    = AVS_CS_PLANAR | AVS_CS_BGR | AVS_CS_RGB_TYPE,                                                // planar RGB
121     AVS_CS_GENERIC_RGBAP   = AVS_CS_PLANAR | AVS_CS_BGR | AVS_CS_RGBA_TYPE,                                               // planar RGBA
122     AVS_CS_GENERIC_YUVA420 = AVS_CS_PLANAR | AVS_CS_YUVA | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2, // 4:2:0:A planar
123     AVS_CS_GENERIC_YUVA422 = AVS_CS_PLANAR | AVS_CS_YUVA | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_2, // 4:2:2:A planar
124     AVS_CS_GENERIC_YUVA444 = AVS_CS_PLANAR | AVS_CS_YUVA | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_1 }; // 4:4:4:A planar
125
126
127   // Specific colorformats
128 enum {
129   AVS_CS_UNKNOWN = 0,
130   AVS_CS_BGR24 = AVS_CS_RGB_TYPE  | AVS_CS_BGR | AVS_CS_INTERLEAVED,
131   AVS_CS_BGR32 = AVS_CS_RGBA_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED,
132   AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
133   //  AVS_CS_YV12  = 1<<3  Reserved
134   //  AVS_CS_I420  = 1<<4  Reserved
135   AVS_CS_RAW32 = 1<<5 | AVS_CS_INTERLEAVED,
136
137   AVS_CS_YV24  = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_8,  // YVU 4:4:4 planar
138   AVS_CS_YV16  = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_8,  // YVU 4:2:2 planar
139   AVS_CS_YV12  = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_8,  // YVU 4:2:0 planar
140   AVS_CS_I420  = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_UPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2,  // YUV 4:2:0 planar
141   AVS_CS_IYUV  = AVS_CS_I420,
142   AVS_CS_YV411 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_4,  // YVU 4:1:1 planar
143   AVS_CS_YUV9  = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_4 | AVS_CS_SUB_WIDTH_4,  // YVU 4:1:0 planar
144   AVS_CS_Y8    = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_8,       // Y   4:0:0 planar
145
146   //-------------------------
147   // AVS16: new planar constants go live! Experimental PF 160613
148   // 10-12-14 bit + planar RGB + BRG48/64 160725
149   AVS_CS_YUV444P10 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_10, // YUV 4:4:4 10bit samples
150   AVS_CS_YUV422P10 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_10, // YUV 4:2:2 10bit samples
151   AVS_CS_YUV420P10 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_10, // YUV 4:2:0 10bit samples
152   AVS_CS_Y10       = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_10,      // Y   4:0:0 10bit samples
153
154   AVS_CS_YUV444P12 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_12, // YUV 4:4:4 12bit samples
155   AVS_CS_YUV422P12 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_12, // YUV 4:2:2 12bit samples
156   AVS_CS_YUV420P12 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_12, // YUV 4:2:0 12bit samples
157   AVS_CS_Y12       = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_12,      // Y   4:0:0 12bit samples
158
159   AVS_CS_YUV444P14 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_14, // YUV 4:4:4 14bit samples
160   AVS_CS_YUV422P14 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_14, // YUV 4:2:2 14bit samples
161   AVS_CS_YUV420P14 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_14, // YUV 4:2:0 14bit samples
162   AVS_CS_Y14       = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_14,      // Y   4:0:0 14bit samples
163
164   AVS_CS_YUV444P16 = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_16, // YUV 4:4:4 16bit samples
165   AVS_CS_YUV422P16 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_16, // YUV 4:2:2 16bit samples
166   AVS_CS_YUV420P16 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_16, // YUV 4:2:0 16bit samples
167   AVS_CS_Y16       = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_16,      // Y   4:0:0 16bit samples
168
169   // 32 bit samples (float)
170   AVS_CS_YUV444PS = AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_32,  // YUV 4:4:4 32bit samples
171   AVS_CS_YUV422PS = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_32,  // YUV 4:2:2 32bit samples
172   AVS_CS_YUV420PS = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_32,  // YUV 4:2:0 32bit samples
173   AVS_CS_Y32      = AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_32,       // Y   4:0:0 32bit samples
174
175   // RGB packed
176   AVS_CS_BGR48 = AVS_CS_RGB_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED | AVS_CS_SAMPLE_BITS_16,    // BGR 3x16 bit
177   AVS_CS_BGR64 = AVS_CS_RGBA_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED | AVS_CS_SAMPLE_BITS_16,    // BGR 4x16 bit
178   // no packed 32 bit (float) support for these legacy types
179
180   // RGB planar
181   AVS_CS_RGBP   = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_8,  // Planar RGB 8 bit samples
182   AVS_CS_RGBP10 = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_10, // Planar RGB 10bit samples
183   AVS_CS_RGBP12 = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_12, // Planar RGB 12bit samples
184   AVS_CS_RGBP14 = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_14, // Planar RGB 14bit samples
185   AVS_CS_RGBP16 = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_16, // Planar RGB 16bit samples
186   AVS_CS_RGBPS  = AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_32, // Planar RGB 32bit samples
187
188   // RGBA planar
189   AVS_CS_RGBAP   = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_8,  // Planar RGBA 8 bit samples
190   AVS_CS_RGBAP10 = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_10, // Planar RGBA 10bit samples
191   AVS_CS_RGBAP12 = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_12, // Planar RGBA 12bit samples
192   AVS_CS_RGBAP14 = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_14, // Planar RGBA 14bit samples
193   AVS_CS_RGBAP16 = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_16, // Planar RGBA 16bit samples
194   AVS_CS_RGBAPS  = AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_32, // Planar RGBA 32bit samples
195
196   // Planar YUVA
197   AVS_CS_YUVA444    = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_8,  // YUVA 4:4:4 8bit samples
198   AVS_CS_YUVA422    = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_8,  // YUVA 4:2:2 8bit samples
199   AVS_CS_YUVA420    = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_8,  // YUVA 4:2:0 8bit samples
200
201   AVS_CS_YUVA444P10 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:4:4 10bit samples
202   AVS_CS_YUVA422P10 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:2:2 10bit samples
203   AVS_CS_YUVA420P10 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:2:0 10bit samples
204
205   AVS_CS_YUVA444P12 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:4:4 12bit samples
206   AVS_CS_YUVA422P12 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:2:2 12bit samples
207   AVS_CS_YUVA420P12 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:2:0 12bit samples
208
209   AVS_CS_YUVA444P14 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:4:4 14bit samples
210   AVS_CS_YUVA422P14 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:2:2 14bit samples
211   AVS_CS_YUVA420P14 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:2:0 14bit samples
212
213   AVS_CS_YUVA444P16 = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:4:4 16bit samples
214   AVS_CS_YUVA422P16 = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:2:2 16bit samples
215   AVS_CS_YUVA420P16 = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:2:0 16bit samples
216
217   AVS_CS_YUVA444PS  = AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_32,  // YUVA 4:4:4 32bit samples
218   AVS_CS_YUVA422PS  = AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_32,  // YUVA 4:2:2 32bit samples
219   AVS_CS_YUVA420PS  = AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_32,  // YUVA 4:2:0 32bit samples
220
221 };
222
223 enum {
224   AVS_IT_BFF = 1<<0,
225   AVS_IT_TFF = 1<<1,
226   AVS_IT_FIELDBASED = 1<<2};
227
228 enum {
229   AVS_FILTER_TYPE=1,
230   AVS_FILTER_INPUT_COLORSPACE=2,
231   AVS_FILTER_OUTPUT_TYPE=9,
232   AVS_FILTER_NAME=4,
233   AVS_FILTER_AUTHOR=5,
234   AVS_FILTER_VERSION=6,
235   AVS_FILTER_ARGS=7,
236   AVS_FILTER_ARGS_INFO=8,
237   AVS_FILTER_ARGS_DESCRIPTION=10,
238   AVS_FILTER_DESCRIPTION=11};
239
240 enum {  //SUBTYPES
241   AVS_FILTER_TYPE_AUDIO=1,
242   AVS_FILTER_TYPE_VIDEO=2,
243   AVS_FILTER_OUTPUT_TYPE_SAME=3,
244   AVS_FILTER_OUTPUT_TYPE_DIFFERENT=4};
245
246 enum {
247   // New 2.6 explicitly defined cache hints.
248   AVS_CACHE_NOTHING=10, // Do not cache video.
249   AVS_CACHE_WINDOW=11, // Hard protect upto X frames within a range of X from the current frame N.
250   AVS_CACHE_GENERIC=12, // LRU cache upto X frames.
251   AVS_CACHE_FORCE_GENERIC=13, // LRU cache upto X frames, override any previous CACHE_WINDOW.
252
253   AVS_CACHE_GET_POLICY=30, // Get the current policy.
254   AVS_CACHE_GET_WINDOW=31, // Get the current window h_span.
255   AVS_CACHE_GET_RANGE=32, // Get the current generic frame range.
256
257   AVS_CACHE_AUDIO=50, // Explicitly do cache audio, X byte cache.
258   AVS_CACHE_AUDIO_NOTHING=51, // Explicitly do not cache audio.
259   AVS_CACHE_AUDIO_NONE=52, // Audio cache off (auto mode), X byte intial cache.
260   AVS_CACHE_AUDIO_AUTO=53, // Audio cache on (auto mode), X byte intial cache.
261
262   AVS_CACHE_GET_AUDIO_POLICY=70, // Get the current audio policy.
263   AVS_CACHE_GET_AUDIO_SIZE=71, // Get the current audio cache size.
264
265   AVS_CACHE_PREFETCH_FRAME=100, // Queue request to prefetch frame N.
266   AVS_CACHE_PREFETCH_GO=101, // Action video prefetches.
267
268   AVS_CACHE_PREFETCH_AUDIO_BEGIN=120, // Begin queue request transaction to prefetch audio (take critical section).
269   AVS_CACHE_PREFETCH_AUDIO_STARTLO=121, // Set low 32 bits of start.
270   AVS_CACHE_PREFETCH_AUDIO_STARTHI=122, // Set high 32 bits of start.
271   AVS_CACHE_PREFETCH_AUDIO_COUNT=123, // Set low 32 bits of length.
272   AVS_CACHE_PREFETCH_AUDIO_COMMIT=124, // Enqueue request transaction to prefetch audio (release critical section).
273   AVS_CACHE_PREFETCH_AUDIO_GO=125, // Action audio prefetches.
274
275   AVS_CACHE_GETCHILD_CACHE_MODE=200, // Cache ask Child for desired video cache mode.
276   AVS_CACHE_GETCHILD_CACHE_SIZE=201, // Cache ask Child for desired video cache size.
277   AVS_CACHE_GETCHILD_AUDIO_MODE=202, // Cache ask Child for desired audio cache mode.
278   AVS_CACHE_GETCHILD_AUDIO_SIZE=203, // Cache ask Child for desired audio cache size.
279
280   AVS_CACHE_GETCHILD_COST=220, // Cache ask Child for estimated processing cost.
281     AVS_CACHE_COST_ZERO=221, // Child response of zero cost (ptr arithmetic only).
282     AVS_CACHE_COST_UNIT=222, // Child response of unit cost (less than or equal 1 full frame blit).
283     AVS_CACHE_COST_LOW=223, // Child response of light cost. (Fast)
284     AVS_CACHE_COST_MED=224, // Child response of medium cost. (Real time)
285     AVS_CACHE_COST_HI=225, // Child response of heavy cost. (Slow)
286
287   AVS_CACHE_GETCHILD_THREAD_MODE=240, // Cache ask Child for thread safetyness.
288     AVS_CACHE_THREAD_UNSAFE=241, // Only 1 thread allowed for all instances. 2.5 filters default!
289     AVS_CACHE_THREAD_CLASS=242, // Only 1 thread allowed for each instance. 2.6 filters default!
290     AVS_CACHE_THREAD_SAFE=243, //  Allow all threads in any instance.
291     AVS_CACHE_THREAD_OWN=244, // Safe but limit to 1 thread, internally threaded.
292
293   AVS_CACHE_GETCHILD_ACCESS_COST=260, // Cache ask Child for preferred access pattern.
294     AVS_CACHE_ACCESS_RAND=261, // Filter is access order agnostic.
295     AVS_CACHE_ACCESS_SEQ0=262, // Filter prefers sequential access (low cost)
296     AVS_CACHE_ACCESS_SEQ1=263, // Filter needs sequential access (high cost)
297   };
298
299 #ifdef BUILDING_AVSCORE
300 struct AVS_ScriptEnvironment {
301         IScriptEnvironment * env;
302         const char * error;
303         AVS_ScriptEnvironment(IScriptEnvironment * e = 0)
304                 : env(e), error(0) {}
305 };
306 #endif
307
308 typedef struct AVS_Clip AVS_Clip;
309 typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
310
311 /////////////////////////////////////////////////////////////////////
312 //
313 // AVS_VideoInfo
314 //
315
316 // AVS_VideoInfo is layed out identicly to VideoInfo
317 typedef struct AVS_VideoInfo {
318   int width, height;    // width=0 means no video
319   unsigned fps_numerator, fps_denominator;
320   int num_frames;
321
322   int pixel_type;
323
324   int audio_samples_per_second;   // 0 means no audio
325   int sample_type;
326   INT64 num_audio_samples;
327   int nchannels;
328
329   // Imagetype properties
330
331   int image_type;
332 } AVS_VideoInfo;
333
334 // useful functions of the above
335 AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p)
336         { return (p->width!=0); }
337
338 AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p)
339         { return (p->audio_samples_per_second!=0); }
340
341 AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p)
342         { return !!(p->pixel_type&AVS_CS_BGR); }
343
344 AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p)
345         { return ((p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24) && ((p->pixel_type & AVS_CS_SAMPLE_BITS_MASK) == AVS_CS_SAMPLE_BITS_8); }
346
347 AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p)
348        { return ((p->pixel_type&AVS_CS_BGR32)==AVS_CS_BGR32) && ((p->pixel_type & AVS_CS_SAMPLE_BITS_MASK) == AVS_CS_SAMPLE_BITS_8); }
349
350 AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p)
351         { return !!(p->pixel_type&AVS_CS_YUV ); }
352
353 AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
354         { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
355
356 AVSC_API(int, avs_is_rgb48)(const AVS_VideoInfo * p);
357
358 AVSC_API(int, avs_is_rgb64)(const AVS_VideoInfo * p);
359
360 AVSC_API(int, avs_is_yv24)(const AVS_VideoInfo * p);
361
362 AVSC_API(int, avs_is_yv16)(const AVS_VideoInfo * p);
363
364 AVSC_API(int, avs_is_yv12)(const AVS_VideoInfo * p) ;
365
366 AVSC_API(int, avs_is_yv411)(const AVS_VideoInfo * p);
367
368 AVSC_API(int, avs_is_y8)(const AVS_VideoInfo * p);
369
370 AVSC_API(int, avs_is_yuv444p16)(const AVS_VideoInfo * p);
371
372 AVSC_API(int, avs_is_yuv422p16)(const AVS_VideoInfo * p);
373
374 AVSC_API(int, avs_is_yuv420p16)(const AVS_VideoInfo * p);
375
376 AVSC_API(int, avs_is_y16)(const AVS_VideoInfo * p);
377
378 AVSC_API(int, avs_is_yuv444ps)(const AVS_VideoInfo * p);
379
380 AVSC_API(int, avs_is_yuv422ps)(const AVS_VideoInfo * p);
381
382 AVSC_API(int, avs_is_yuv420ps)(const AVS_VideoInfo * p);
383
384 AVSC_API(int, avs_is_y32)(const AVS_VideoInfo * p);
385
386 AVSC_API(int, avs_is_444)(const AVS_VideoInfo * p);
387
388 AVSC_API(int, avs_is_422)(const AVS_VideoInfo * p);
389
390 AVSC_API(int, avs_is_420)(const AVS_VideoInfo * p);
391
392 AVSC_API(int, avs_is_y)(const AVS_VideoInfo * p);
393
394 AVSC_API(int, avs_is_yuva)(const AVS_VideoInfo * p);
395
396 AVSC_API(int, avs_is_planar_rgb)(const AVS_VideoInfo * p);
397
398 AVSC_API(int, avs_is_planar_rgba)(const AVS_VideoInfo * p);
399
400
401
402 AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
403         { return ((p->image_type & property)==property ); }
404
405 AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
406         { return !!(p->pixel_type & AVS_CS_PLANAR); }
407
408 AVSC_API(int, avs_is_color_space)(const AVS_VideoInfo * p, int c_space);
409
410 AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
411         { return !!(p->image_type & AVS_IT_FIELDBASED); }
412
413 AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
414         { return ((p->image_type & AVS_IT_FIELDBASED)&&(p->image_type & (AVS_IT_BFF | AVS_IT_TFF))); }
415
416 AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
417         { return !!(p->image_type & AVS_IT_BFF); }
418
419 AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
420         { return !!(p->image_type & AVS_IT_TFF); }
421
422 AVSC_API(int, avs_get_plane_width_subsampling)(const AVS_VideoInfo * p, int plane);
423
424 AVSC_API(int, avs_get_plane_height_subsampling)(const AVS_VideoInfo * p, int plane);
425
426
427 AVSC_API(int, avs_bits_per_pixel)(const AVS_VideoInfo * p);
428
429 AVSC_API(int, avs_bytes_from_pixels)(const AVS_VideoInfo * p, int pixels);
430
431 AVSC_API(int, avs_row_size)(const AVS_VideoInfo * p, int plane);
432
433 AVSC_API(int, avs_bmp_size)(const AVS_VideoInfo * vi);
434
435 AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
436         { return p->audio_samples_per_second; }
437
438
439 AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
440 {
441     switch (p->sample_type) {
442       case AVS_SAMPLE_INT8:  return sizeof(signed char);
443       case AVS_SAMPLE_INT16: return sizeof(signed short);
444       case AVS_SAMPLE_INT24: return 3;
445       case AVS_SAMPLE_INT32: return sizeof(signed int);
446       case AVS_SAMPLE_FLOAT: return sizeof(float);
447       default: return 0;
448     }
449 }
450 AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
451         { return p->nchannels*avs_bytes_per_channel_sample(p);}
452
453 AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames)
454         { return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
455
456 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
457         { return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); }
458
459 AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes)
460         { return bytes / avs_bytes_per_audio_sample(p); }
461
462 AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
463         { return samples * avs_bytes_per_audio_sample(p); }
464
465 AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
466         { return p->nchannels; }
467
468 AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
469         { return p->sample_type;}
470
471 // useful mutator
472 AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
473         { p->image_type|=property; }
474
475 AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)
476         { p->image_type&=~property; }
477
478 AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)
479         { if (isfieldbased) p->image_type|=AVS_IT_FIELDBASED; else p->image_type&=~AVS_IT_FIELDBASED; }
480
481 AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator)
482 {
483     unsigned x=numerator, y=denominator;
484     while (y) {   // find gcd
485       unsigned t = x%y; x = y; y = t;
486     }
487     p->fps_numerator = numerator/x;
488     p->fps_denominator = denominator/x;
489 }
490
491 #ifdef AVS_IMPLICIT_FUNCTION_DECLARATION_ERROR
492 AVSC_INLINE int avs_is_same_colorspace(AVS_VideoInfo * x, AVS_VideoInfo * y)
493 {
494         return (x->pixel_type == y->pixel_type)
495                 || (avs_is_yv12(x) && avs_is_yv12(y));
496 }
497 #endif
498
499 AVSC_API(int, avs_num_components)(const AVS_VideoInfo * p);
500
501 AVSC_API(int, avs_component_size)(const AVS_VideoInfo * p);
502
503 AVSC_API(int, avs_bits_per_component)(const AVS_VideoInfo * p);
504
505 /////////////////////////////////////////////////////////////////////
506 //
507 // AVS_VideoFrame
508 //
509
510 // VideoFrameBuffer holds information about a memory block which is used
511 // for video data.  For efficiency, instances of this class are not deleted
512 // when the refcount reaches zero; instead they're stored in a linked list
513 // to be reused.  The instances are deleted when the corresponding AVS
514 // file is closed.
515
516 // AVS_VideoFrameBuffer is layed out identicly to VideoFrameBuffer
517 // DO NOT USE THIS STRUCTURE DIRECTLY
518 typedef struct AVS_VideoFrameBuffer {
519   BYTE * data;
520   int data_size;
521   // sequence_number is incremented every time the buffer is changed, so
522   // that stale views can tell they're no longer valid.
523   volatile long sequence_number;
524
525   volatile long refcount;
526 } AVS_VideoFrameBuffer;
527
528 // VideoFrame holds a "window" into a VideoFrameBuffer.
529
530 // AVS_VideoFrame is layed out identicly to IVideoFrame
531 // DO NOT USE THIS STRUCTURE DIRECTLY
532 typedef struct AVS_VideoFrame {
533   volatile long refcount;
534   AVS_VideoFrameBuffer * vfb;
535   int offset, pitch, row_size, height, offsetU, offsetV, pitchUV;  // U&V offsets are from top of picture.
536   int row_sizeUV, heightUV;
537 } AVS_VideoFrame;
538
539 // Access functions for AVS_VideoFrame
540 AVSC_API(int, avs_get_pitch_p)(const AVS_VideoFrame * p, int plane);
541
542 #ifdef AVS_IMPLICIT_FUNCTION_DECLARATION_ERROR
543 AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p) {
544         return avs_get_pitch_p(p, 0);}
545 #endif
546
547 AVSC_API(int, avs_get_row_size_p)(const AVS_VideoFrame * p, int plane);
548
549 AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p) {
550         return p->row_size; }
551
552 AVSC_API(int, avs_get_height_p)(const AVS_VideoFrame * p, int plane);
553
554 AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p) {
555         return p->height;}
556
557 AVSC_API(const BYTE *, avs_get_read_ptr_p)(const AVS_VideoFrame * p, int plane);
558
559 #ifdef AVS_IMPLICIT_FUNCTION_DECLARATION_ERROR
560 AVSC_INLINE const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p) {
561         return avs_get_read_ptr_p(p, 0);}
562 #endif
563
564 AVSC_API(int, avs_is_writable)(const AVS_VideoFrame * p);
565
566 AVSC_API(BYTE *, avs_get_write_ptr_p)(const AVS_VideoFrame * p, int plane);
567
568 #ifdef AVS_IMPLICIT_FUNCTION_DECLARATION_ERROR
569 AVSC_INLINE BYTE* avs_get_write_ptr(const AVS_VideoFrame * p) {
570         return avs_get_write_ptr_p(p, 0);}
571 #endif
572
573 AVSC_API(void, avs_release_video_frame)(AVS_VideoFrame *);
574 // makes a shallow copy of a video frame
575 AVSC_API(AVS_VideoFrame *, avs_copy_video_frame)(AVS_VideoFrame *);
576
577 #ifndef AVSC_NO_DECLSPEC
578 AVSC_INLINE void avs_release_frame(AVS_VideoFrame * f)
579   {avs_release_video_frame(f);}
580 AVSC_INLINE AVS_VideoFrame * avs_copy_frame(AVS_VideoFrame * f)
581   {return avs_copy_video_frame(f);}
582 #endif
583
584 /////////////////////////////////////////////////////////////////////
585 //
586 // AVS_Value
587 //
588
589 // Treat AVS_Value as a fat pointer.  That is use avs_copy_value
590 // and avs_release_value appropiaty as you would if AVS_Value was
591 // a pointer.
592
593 // To maintain source code compatibility with future versions of the
594 // avisynth_c API don't use the AVS_Value directly.  Use the helper
595 // functions below.
596
597 // AVS_Value is layed out identicly to AVSValue
598 typedef struct AVS_Value AVS_Value;
599 struct AVS_Value {
600   short type;  // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
601                // for some function e'rror
602   short array_size;
603   union {
604     void * clip; // do not use directly, use avs_take_clip
605     char boolean;
606     int integer;
607     float floating_pt;
608     const char * string;
609     const AVS_Value * array;
610   } d;
611 };
612
613 // AVS_Value should be initilized with avs_void.
614 // Should also set to avs_void after the value is released
615 // with avs_copy_value.  Consider it the equalvent of setting
616 // a pointer to NULL
617 static const AVS_Value avs_void = {'v'};
618
619 AVSC_API(void, avs_copy_value)(AVS_Value * dest, AVS_Value src);
620 AVSC_API(void, avs_release_value)(AVS_Value);
621
622 AVSC_INLINE int avs_defined(AVS_Value v) { return v.type != 'v'; }
623 AVSC_INLINE int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
624 AVSC_INLINE int avs_is_bool(AVS_Value v) { return v.type == 'b'; }
625 AVSC_INLINE int avs_is_int(AVS_Value v) { return v.type == 'i'; }
626 AVSC_INLINE int avs_is_float(AVS_Value v) { return v.type == 'f' || v.type == 'i'; }
627 AVSC_INLINE int avs_is_string(AVS_Value v) { return v.type == 's'; }
628 AVSC_INLINE int avs_is_array(AVS_Value v) { return v.type == 'a'; }
629 AVSC_INLINE int avs_is_error(AVS_Value v) { return v.type == 'e'; }
630
631 AVSC_API(AVS_Clip *, avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
632 AVSC_API(void, avs_set_to_clip)(AVS_Value *, AVS_Clip *);
633
634 AVSC_INLINE int avs_as_bool(AVS_Value v)
635         { return v.d.boolean; }
636 AVSC_INLINE int avs_as_int(AVS_Value v)
637         { return v.d.integer; }
638 AVSC_INLINE const char * avs_as_string(AVS_Value v)
639         { return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
640 AVSC_INLINE double avs_as_float(AVS_Value v)
641         { return avs_is_int(v) ? v.d.integer : v.d.floating_pt; }
642 AVSC_INLINE const char * avs_as_error(AVS_Value v)
643         { return avs_is_error(v) ? v.d.string : 0; }
644 AVSC_INLINE const AVS_Value * avs_as_array(AVS_Value v)
645         { return v.d.array; }
646 AVSC_INLINE int avs_array_size(AVS_Value v)
647         { return avs_is_array(v) ? v.array_size : 1; }
648 AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index)
649         { return avs_is_array(v) ? v.d.array[index] : v; }
650
651 // only use these functions on an AVS_Value that does not already have
652 // an active value.  Remember, treat AVS_Value as a fat pointer.
653 AVSC_INLINE AVS_Value avs_new_value_bool(int v0)
654         { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
655 AVSC_INLINE AVS_Value avs_new_value_int(int v0)
656         { AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }
657 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
658         { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
659 AVSC_INLINE AVS_Value avs_new_value_float(float v0)
660         { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
661 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
662         { AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
663 #ifndef AVSC_NO_DECLSPEC
664 AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
665         { AVS_Value v; avs_set_to_clip(&v, v0); return v; }
666 #endif
667 AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
668         { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = (short)size; return v; }
669
670 /////////////////////////////////////////////////////////////////////
671 //
672 // AVS_Clip
673 //
674
675 AVSC_API(void, avs_release_clip)(AVS_Clip *);
676 AVSC_API(AVS_Clip *, avs_copy_clip)(AVS_Clip *);
677
678 AVSC_API(const char *, avs_clip_get_error)(AVS_Clip *); // return 0 if no error
679
680 AVSC_API(const AVS_VideoInfo *, avs_get_video_info)(AVS_Clip *);
681
682 AVSC_API(int, avs_get_version)(AVS_Clip *);
683
684 AVSC_API(AVS_VideoFrame *, avs_get_frame)(AVS_Clip *, int n);
685 // The returned video frame must be released with avs_release_video_frame
686
687 AVSC_API(int, avs_get_parity)(AVS_Clip *, int n);
688 // return field parity if field_based, else parity of first field in frame
689
690 AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf,
691                              INT64 start, INT64 count);
692 // start and count are in samples
693
694 AVSC_API(int, avs_set_cache_hints)(AVS_Clip *,
695                                    int cachehints, int frame_range);
696
697 // This is the callback type used by avs_add_function
698 typedef AVS_Value (AVSC_CC * AVS_ApplyFunc)
699                         (AVS_ScriptEnvironment *, AVS_Value args, void * user_data);
700
701 typedef struct AVS_FilterInfo AVS_FilterInfo;
702 struct AVS_FilterInfo
703 {
704   // these members should not be modified outside of the AVS_ApplyFunc callback
705   AVS_Clip * child;
706   AVS_VideoInfo vi;
707   AVS_ScriptEnvironment * env;
708   AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n);
709   int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n);
710   int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf,
711                                   INT64 start, INT64 count);
712   int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints,
713                                         int frame_range);
714   void (AVSC_CC * free_filter)(AVS_FilterInfo *);
715
716   // Should be set when ever there is an error to report.
717   // It is cleared before any of the above methods are called
718   const char * error;
719   // this is to store whatever and may be modified at will
720   void * user_data;
721 };
722
723 // Create a new filter
724 // fi is set to point to the AVS_FilterInfo so that you can
725 //   modify it once it is initilized.
726 // store_child should generally be set to true.  If it is not
727 //    set than ALL methods (the function pointers) must be defined
728 // If it is set than you do not need to worry about freeing the child
729 //    clip.
730 AVSC_API(AVS_Clip *, avs_new_c_filter)(AVS_ScriptEnvironment * e,
731                                        AVS_FilterInfo * * fi,
732                                        AVS_Value child, int store_child);
733
734 /////////////////////////////////////////////////////////////////////
735 //
736 // AVS_ScriptEnvironment
737 //
738
739 // For GetCPUFlags.  These are backwards-compatible with those in VirtualDub.
740 enum {
741                                 /* slowest CPU to support extension */
742   AVS_CPU_FORCE        = 0x01,   // N/A
743   AVS_CPU_FPU          = 0x02,   // 386/486DX
744   AVS_CPU_MMX          = 0x04,   // P55C, K6, PII
745   AVS_CPU_INTEGER_SSE  = 0x08,   // PIII, Athlon
746   AVS_CPU_SSE          = 0x10,   // PIII, Athlon XP/MP
747   AVS_CPU_SSE2         = 0x20,   // PIV, Hammer
748   AVS_CPU_3DNOW        = 0x40,   // K6-2
749   AVS_CPU_3DNOW_EXT    = 0x80,   // Athlon
750   AVS_CPU_X86_64       = 0xA0,   // Hammer (note: equiv. to 3DNow + SSE2,
751                                  // which only Hammer will have anyway)
752   AVS_CPUF_SSE3       = 0x100,   //  PIV+, K8 Venice
753   AVS_CPUF_SSSE3      = 0x200,   //  Core 2
754   AVS_CPUF_SSE4       = 0x400,   //  Penryn, Wolfdale, Yorkfield
755   AVS_CPUF_SSE4_1     = 0x400,
756 //AVS_CPUF_AVX        = 0x800,   //  Sandy Bridge, Bulldozer
757   AVS_CPUF_SSE4_2    = 0x1000,   //  Nehalem
758 //AVS_CPUF_AVX2      = 0x2000,   //  Haswell
759 //AVS_CPUF_AVX512    = 0x4000,   //  Knights Landing
760 };
761
762
763 AVSC_API(const char *, avs_get_error)(AVS_ScriptEnvironment *); // return 0 if no error
764
765 AVSC_API(int, avs_get_cpu_flags)(AVS_ScriptEnvironment *);
766 AVSC_API(int, avs_check_version)(AVS_ScriptEnvironment *, int version);
767
768 AVSC_API(char *, avs_save_string)(AVS_ScriptEnvironment *, const char* s, int length);
769 AVSC_API(char *, avs_sprintf)(AVS_ScriptEnvironment *, const char * fmt, ...);
770
771 AVSC_API(char *, avs_vsprintf)(AVS_ScriptEnvironment *, const char * fmt, void* val);
772  // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
773
774 AVSC_API(int, avs_add_function)(AVS_ScriptEnvironment *,
775                                 const char * name, const char * params,
776                                 AVS_ApplyFunc apply, void * user_data);
777
778 AVSC_API(int, avs_function_exists)(AVS_ScriptEnvironment *, const char * name);
779
780 AVSC_API(AVS_Value, avs_invoke)(AVS_ScriptEnvironment *, const char * name,
781                                AVS_Value args, const char** arg_names);
782 // The returned value must be be released with avs_release_value
783
784 AVSC_API(AVS_Value, avs_get_var)(AVS_ScriptEnvironment *, const char* name);
785 // The returned value must be be released with avs_release_value
786
787 AVSC_API(int, avs_set_var)(AVS_ScriptEnvironment *, const char* name, AVS_Value val);
788
789 AVSC_API(int, avs_set_global_var)(AVS_ScriptEnvironment *, const char* name, const AVS_Value val);
790
791 //void avs_push_context(AVS_ScriptEnvironment *, int level=0);
792 //void avs_pop_context(AVS_ScriptEnvironment *);
793
794 AVSC_API(AVS_VideoFrame *, avs_new_video_frame_a)(AVS_ScriptEnvironment *,
795                                           const AVS_VideoInfo * vi, int align);
796 // align should be at least 16
797
798 #ifndef AVSC_NO_DECLSPEC
799 AVSC_INLINE
800 AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
801                                      const AVS_VideoInfo * vi)
802   {return avs_new_video_frame_a(env,vi,FRAME_ALIGN);}
803
804 AVSC_INLINE
805 AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
806                                const AVS_VideoInfo * vi)
807   {return avs_new_video_frame_a(env,vi,FRAME_ALIGN);}
808 #endif
809
810
811 AVSC_API(int, avs_make_writable)(AVS_ScriptEnvironment *, AVS_VideoFrame * * pvf);
812
813 AVSC_API(void, avs_bit_blt)(AVS_ScriptEnvironment *, BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height);
814
815 typedef void (AVSC_CC *AVS_ShutdownFunc)(void* user_data, AVS_ScriptEnvironment * env);
816 AVSC_API(void, avs_at_exit)(AVS_ScriptEnvironment *, AVS_ShutdownFunc function, void * user_data);
817
818 AVSC_API(AVS_VideoFrame *, avs_subframe)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height);
819 // The returned video frame must be be released
820
821 AVSC_API(int, avs_set_memory_max)(AVS_ScriptEnvironment *, int mem);
822
823 AVSC_API(int, avs_set_working_dir)(AVS_ScriptEnvironment *, const char * newdir);
824
825 // avisynth.dll exports this; it's a way to use it as a library, without
826 // writing an AVS script or without going through AVIFile.
827 AVSC_API(AVS_ScriptEnvironment *, avs_create_script_environment)(int version);
828
829 // this symbol is the entry point for the plugin and must
830 // be defined
831 AVSC_EXPORT
832 const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment* env);
833
834
835 AVSC_API(void, avs_delete_script_environment)(AVS_ScriptEnvironment *);
836
837
838 AVSC_API(AVS_VideoFrame *, avs_subframe_planar)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV);
839 // The returned video frame must be be released
840
841 #ifdef AVSC_NO_DECLSPEC
842 // use LoadLibrary and related functions to dynamically load Avisynth instead of declspec(dllimport)
843 /*
844   The following functions needs to have been declared, probably from windows.h
845
846   void* malloc(size_t)
847   void free(void*);
848
849   HMODULE LoadLibrary(const char*);
850   void* GetProcAddress(HMODULE, const char*);
851   FreeLibrary(HMODULE);
852 */
853
854
855 typedef struct AVS_Library AVS_Library;
856
857 #define AVSC_DECLARE_FUNC(name) name##_func name
858
859 struct AVS_Library {
860   HMODULE handle;
861
862   AVSC_DECLARE_FUNC(avs_add_function);
863   AVSC_DECLARE_FUNC(avs_at_exit);
864   AVSC_DECLARE_FUNC(avs_bit_blt);
865   AVSC_DECLARE_FUNC(avs_check_version);
866   AVSC_DECLARE_FUNC(avs_clip_get_error);
867   AVSC_DECLARE_FUNC(avs_copy_clip);
868   AVSC_DECLARE_FUNC(avs_copy_value);
869   AVSC_DECLARE_FUNC(avs_copy_video_frame);
870   AVSC_DECLARE_FUNC(avs_create_script_environment);
871   AVSC_DECLARE_FUNC(avs_delete_script_environment);
872   AVSC_DECLARE_FUNC(avs_function_exists);
873   AVSC_DECLARE_FUNC(avs_get_audio);
874   AVSC_DECLARE_FUNC(avs_get_cpu_flags);
875   AVSC_DECLARE_FUNC(avs_get_frame);
876   AVSC_DECLARE_FUNC(avs_get_parity);
877   AVSC_DECLARE_FUNC(avs_get_var);
878   AVSC_DECLARE_FUNC(avs_get_version);
879   AVSC_DECLARE_FUNC(avs_get_video_info);
880   AVSC_DECLARE_FUNC(avs_invoke);
881   AVSC_DECLARE_FUNC(avs_make_writable);
882   AVSC_DECLARE_FUNC(avs_new_c_filter);
883   AVSC_DECLARE_FUNC(avs_new_video_frame_a);
884   AVSC_DECLARE_FUNC(avs_release_clip);
885   AVSC_DECLARE_FUNC(avs_release_value);
886   AVSC_DECLARE_FUNC(avs_release_video_frame);
887   AVSC_DECLARE_FUNC(avs_save_string);
888   AVSC_DECLARE_FUNC(avs_set_cache_hints);
889   AVSC_DECLARE_FUNC(avs_set_global_var);
890   AVSC_DECLARE_FUNC(avs_set_memory_max);
891   AVSC_DECLARE_FUNC(avs_set_to_clip);
892   AVSC_DECLARE_FUNC(avs_set_var);
893   AVSC_DECLARE_FUNC(avs_set_working_dir);
894   AVSC_DECLARE_FUNC(avs_sprintf);
895   AVSC_DECLARE_FUNC(avs_subframe);
896   AVSC_DECLARE_FUNC(avs_subframe_planar);
897   AVSC_DECLARE_FUNC(avs_take_clip);
898   AVSC_DECLARE_FUNC(avs_vsprintf);
899
900   AVSC_DECLARE_FUNC(avs_get_error);
901   AVSC_DECLARE_FUNC(avs_is_rgb48);
902   AVSC_DECLARE_FUNC(avs_is_rgb64);
903   AVSC_DECLARE_FUNC(avs_is_yv24);
904   AVSC_DECLARE_FUNC(avs_is_yv16);
905   AVSC_DECLARE_FUNC(avs_is_yv12);
906   AVSC_DECLARE_FUNC(avs_is_yv411);
907   AVSC_DECLARE_FUNC(avs_is_y8);
908   AVSC_DECLARE_FUNC(avs_is_yuv444p16);
909   AVSC_DECLARE_FUNC(avs_is_yuv422p16);
910   AVSC_DECLARE_FUNC(avs_is_yuv420p16);
911   AVSC_DECLARE_FUNC(avs_is_y16);
912   AVSC_DECLARE_FUNC(avs_is_yuv444ps);
913   AVSC_DECLARE_FUNC(avs_is_yuv422ps);
914   AVSC_DECLARE_FUNC(avs_is_yuv420ps);
915   AVSC_DECLARE_FUNC(avs_is_y32);
916   AVSC_DECLARE_FUNC(avs_is_444);
917   AVSC_DECLARE_FUNC(avs_is_422);
918   AVSC_DECLARE_FUNC(avs_is_420);
919   AVSC_DECLARE_FUNC(avs_is_y);
920   AVSC_DECLARE_FUNC(avs_is_yuva);
921   AVSC_DECLARE_FUNC(avs_is_planar_rgb);
922   AVSC_DECLARE_FUNC(avs_is_planar_rgba);
923   AVSC_DECLARE_FUNC(avs_is_color_space);
924
925   AVSC_DECLARE_FUNC(avs_get_plane_width_subsampling);
926   AVSC_DECLARE_FUNC(avs_get_plane_height_subsampling);
927   AVSC_DECLARE_FUNC(avs_bits_per_pixel);
928   AVSC_DECLARE_FUNC(avs_bytes_from_pixels);
929   AVSC_DECLARE_FUNC(avs_row_size);
930   AVSC_DECLARE_FUNC(avs_bmp_size);
931   AVSC_DECLARE_FUNC(avs_get_pitch_p);
932   AVSC_DECLARE_FUNC(avs_get_row_size_p);
933   AVSC_DECLARE_FUNC(avs_get_height_p);
934   AVSC_DECLARE_FUNC(avs_get_read_ptr_p);
935   AVSC_DECLARE_FUNC(avs_is_writable);
936   AVSC_DECLARE_FUNC(avs_get_write_ptr_p);
937
938   AVSC_DECLARE_FUNC(avs_num_components);
939   AVSC_DECLARE_FUNC(avs_component_size);
940   AVSC_DECLARE_FUNC(avs_bits_per_component);
941
942 };
943
944 #undef AVSC_DECLARE_FUNC
945
946
947 AVSC_INLINE AVS_Library * avs_load_library() {
948   AVS_Library *library = (AVS_Library *)malloc(sizeof(AVS_Library));
949   if (library == NULL)
950     return NULL;
951   library->handle = LoadLibrary("avisynth");
952   if (library->handle == NULL)
953     goto fail;
954
955 #define __AVSC_STRINGIFY(x) #x
956 #define AVSC_STRINGIFY(x) __AVSC_STRINGIFY(x)
957 #define AVSC_LOAD_FUNC(name) {\
958   library->name = (name##_func) GetProcAddress(library->handle, AVSC_STRINGIFY(name));\
959   if (library->name == NULL)\
960     goto fail;\
961 }
962
963   AVSC_LOAD_FUNC(avs_add_function);
964   AVSC_LOAD_FUNC(avs_at_exit);
965   AVSC_LOAD_FUNC(avs_bit_blt);
966   AVSC_LOAD_FUNC(avs_check_version);
967   AVSC_LOAD_FUNC(avs_clip_get_error);
968   AVSC_LOAD_FUNC(avs_copy_clip);
969   AVSC_LOAD_FUNC(avs_copy_value);
970   AVSC_LOAD_FUNC(avs_copy_video_frame);
971   AVSC_LOAD_FUNC(avs_create_script_environment);
972   AVSC_LOAD_FUNC(avs_delete_script_environment);
973   AVSC_LOAD_FUNC(avs_function_exists);
974   AVSC_LOAD_FUNC(avs_get_audio);
975   AVSC_LOAD_FUNC(avs_get_cpu_flags);
976   AVSC_LOAD_FUNC(avs_get_frame);
977   AVSC_LOAD_FUNC(avs_get_parity);
978   AVSC_LOAD_FUNC(avs_get_var);
979   AVSC_LOAD_FUNC(avs_get_version);
980   AVSC_LOAD_FUNC(avs_get_video_info);
981   AVSC_LOAD_FUNC(avs_invoke);
982   AVSC_LOAD_FUNC(avs_make_writable);
983   AVSC_LOAD_FUNC(avs_new_c_filter);
984   AVSC_LOAD_FUNC(avs_new_video_frame_a);
985   AVSC_LOAD_FUNC(avs_release_clip);
986   AVSC_LOAD_FUNC(avs_release_value);
987   AVSC_LOAD_FUNC(avs_release_video_frame);
988   AVSC_LOAD_FUNC(avs_save_string);
989   AVSC_LOAD_FUNC(avs_set_cache_hints);
990   AVSC_LOAD_FUNC(avs_set_global_var);
991   AVSC_LOAD_FUNC(avs_set_memory_max);
992   AVSC_LOAD_FUNC(avs_set_to_clip);
993   AVSC_LOAD_FUNC(avs_set_var);
994   AVSC_LOAD_FUNC(avs_set_working_dir);
995   AVSC_LOAD_FUNC(avs_sprintf);
996   AVSC_LOAD_FUNC(avs_subframe);
997   AVSC_LOAD_FUNC(avs_subframe_planar);
998   AVSC_LOAD_FUNC(avs_take_clip);
999   AVSC_LOAD_FUNC(avs_vsprintf);
1000
1001   AVSC_LOAD_FUNC(avs_get_error);
1002   AVSC_LOAD_FUNC(avs_is_rgb48);
1003   AVSC_LOAD_FUNC(avs_is_rgb64);
1004   AVSC_LOAD_FUNC(avs_is_yv24);
1005   AVSC_LOAD_FUNC(avs_is_yv16);
1006   AVSC_LOAD_FUNC(avs_is_yv12);
1007   AVSC_LOAD_FUNC(avs_is_yv411);
1008   AVSC_LOAD_FUNC(avs_is_y8);
1009   AVSC_LOAD_FUNC(avs_is_yuv444p16);
1010   AVSC_LOAD_FUNC(avs_is_yuv422p16);
1011   AVSC_LOAD_FUNC(avs_is_yuv420p16);
1012   AVSC_LOAD_FUNC(avs_is_y16);
1013   AVSC_LOAD_FUNC(avs_is_yuv444ps);
1014   AVSC_LOAD_FUNC(avs_is_yuv422ps);
1015   AVSC_LOAD_FUNC(avs_is_yuv420ps);
1016   AVSC_LOAD_FUNC(avs_is_y32);
1017   AVSC_LOAD_FUNC(avs_is_444);
1018   AVSC_LOAD_FUNC(avs_is_422);
1019   AVSC_LOAD_FUNC(avs_is_420);
1020   AVSC_LOAD_FUNC(avs_is_y);
1021   AVSC_LOAD_FUNC(avs_is_yuva);
1022   AVSC_LOAD_FUNC(avs_is_planar_rgb);
1023   AVSC_LOAD_FUNC(avs_is_planar_rgba);
1024   AVSC_LOAD_FUNC(avs_is_color_space);
1025
1026   AVSC_LOAD_FUNC(avs_get_plane_width_subsampling);
1027   AVSC_LOAD_FUNC(avs_get_plane_height_subsampling);
1028   AVSC_LOAD_FUNC(avs_bits_per_pixel);
1029   AVSC_LOAD_FUNC(avs_bytes_from_pixels);
1030   AVSC_LOAD_FUNC(avs_row_size);
1031   AVSC_LOAD_FUNC(avs_bmp_size);
1032   AVSC_LOAD_FUNC(avs_get_pitch_p);
1033   AVSC_LOAD_FUNC(avs_get_row_size_p);
1034   AVSC_LOAD_FUNC(avs_get_height_p);
1035   AVSC_LOAD_FUNC(avs_get_read_ptr_p);
1036   AVSC_LOAD_FUNC(avs_is_writable);
1037   AVSC_LOAD_FUNC(avs_get_write_ptr_p);
1038
1039   AVSC_LOAD_FUNC(avs_num_components);
1040   AVSC_LOAD_FUNC(avs_component_size);
1041   AVSC_LOAD_FUNC(avs_bits_per_component);
1042
1043
1044
1045 #undef __AVSC_STRINGIFY
1046 #undef AVSC_STRINGIFY
1047 #undef AVSC_LOAD_FUNC
1048
1049   return library;
1050
1051 fail:
1052   free(library);
1053   return NULL;
1054 }
1055
1056 AVSC_INLINE void avs_free_library(AVS_Library *library) {
1057   if (library == NULL)
1058     return;
1059   FreeLibrary(library->handle);
1060   free(library);
1061 }
1062 #endif
1063
1064 #endif