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., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
17 // http://www.gnu.org/copyleft/gpl.html .
18 //
19 // As a special exception, I give you permission to link to the
20 // Avisynth C interface with independent modules that communicate with
21 // the Avisynth C interface solely through the interfaces defined in
22 // avisynth_c.h, regardless of the license terms of these independent
23 // modules, and to copy and distribute the resulting combined work
24 // under terms of your choice, provided that every copy of the
25 // combined work is accompanied by a complete copy of the source code
26 // of the Avisynth C interface and Avisynth itself (with the version
27 // used to produce the combined work), being distributed under the
28 // terms of the GNU General Public License plus this exception. An
29 // independent module is a module which is not derived from or based
30 // on Avisynth C Interface, such as 3rd-party filters, import and
31 // export plugins, or graphical user interfaces.
32
33 // NOTE: this is a partial update of the Avisynth C interface to recognize
34 // new color spaces added in Avisynth 2.60. By no means is this document
35 // completely Avisynth 2.60 compliant.
36
37 #ifndef __AVISYNTH_C__
38 #define __AVISYNTH_C__
39
40 #ifdef __cplusplus
41 # define EXTERN_C extern "C"
42 #else
43 # define EXTERN_C
44 #endif
45
46 #define AVSC_USE_STDCALL 1
47
48 #ifndef AVSC_USE_STDCALL
49 # define AVSC_CC __cdecl
50 #else
51 # define AVSC_CC __stdcall
52 #endif
53
54 #define AVSC_INLINE static __inline
55
56 #ifdef AVISYNTH_C_EXPORTS
57 # define AVSC_EXPORT EXTERN_C
58 # define AVSC_API(ret, name) EXTERN_C __declspec(dllexport) ret AVSC_CC name
59 #else
60 # define AVSC_EXPORT EXTERN_C __declspec(dllexport)
61 # ifndef AVSC_NO_DECLSPEC
62 # define AVSC_API(ret, name) EXTERN_C __declspec(dllimport) ret AVSC_CC name
63 # else
64 # define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func)
65 # endif
66 #endif
67
68 typedef unsigned char BYTE;
69 #ifdef __GNUC__
70 typedef long long int INT64;
71 #else
72 typedef __int64 INT64;
73 #endif
74
75
76 /////////////////////////////////////////////////////////////////////
77 //
78 // Constants
79 //
80
81 #ifndef __AVISYNTH_H__
82 enum { AVISYNTH_INTERFACE_VERSION = 4 };
83 #endif
84
85 enum {AVS_SAMPLE_INT8 = 1<<0,
86 AVS_SAMPLE_INT16 = 1<<1,
87 AVS_SAMPLE_INT24 = 1<<2,
88 AVS_SAMPLE_INT32 = 1<<3,
89 AVS_SAMPLE_FLOAT = 1<<4};
90
91 enum {AVS_PLANAR_Y=1<<0,
92 AVS_PLANAR_U=1<<1,
93 AVS_PLANAR_V=1<<2,
94 AVS_PLANAR_ALIGNED=1<<3,
95 AVS_PLANAR_Y_ALIGNED=AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
96 AVS_PLANAR_U_ALIGNED=AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
97 AVS_PLANAR_V_ALIGNED=AVS_PLANAR_V|AVS_PLANAR_ALIGNED,
98 AVS_PLANAR_A=1<<4,
99 AVS_PLANAR_R=1<<5,
100 AVS_PLANAR_G=1<<6,
101 AVS_PLANAR_B=1<<7,
102 AVS_PLANAR_A_ALIGNED=AVS_PLANAR_A|AVS_PLANAR_ALIGNED,
103 AVS_PLANAR_R_ALIGNED=AVS_PLANAR_R|AVS_PLANAR_ALIGNED,
104 AVS_PLANAR_G_ALIGNED=AVS_PLANAR_G|AVS_PLANAR_ALIGNED,
105 AVS_PLANAR_B_ALIGNED=AVS_PLANAR_B|AVS_PLANAR_ALIGNED};
106
107 // Colorspace properties.
108 enum {AVS_CS_BGR = 1<<28,
109 AVS_CS_YUV = 1<<29,
110 AVS_CS_INTERLEAVED = 1<<30,
111 AVS_CS_PLANAR = (int)(1u<<31),
112
113 AVS_CS_SHIFT_SUB_WIDTH = 0,
114 AVS_CS_SHIFT_SUB_HEIGHT = 1 << 3,
115 AVS_CS_SHIFT_SAMPLE_BITS = 1 << 4,
116
117 AVS_CS_SUB_WIDTH_MASK = 7 << AVS_CS_SHIFT_SUB_WIDTH,
118 AVS_CS_SUB_WIDTH_1 = 3 << AVS_CS_SHIFT_SUB_WIDTH, // YV24
119 AVS_CS_SUB_WIDTH_2 = 0 << AVS_CS_SHIFT_SUB_WIDTH, // YV12, I420, YV16
120 AVS_CS_SUB_WIDTH_4 = 1 << AVS_CS_SHIFT_SUB_WIDTH, // YUV9, YV411
121
122 AVS_CS_VPLANEFIRST = 1 << 3, // YV12, YV16, YV24, YV411, YUV9
123 AVS_CS_UPLANEFIRST = 1 << 4, // I420
124
125 AVS_CS_SUB_HEIGHT_MASK = 7 << AVS_CS_SHIFT_SUB_HEIGHT,
126 AVS_CS_SUB_HEIGHT_1 = 3 << AVS_CS_SHIFT_SUB_HEIGHT, // YV16, YV24, YV411
127 AVS_CS_SUB_HEIGHT_2 = 0 << AVS_CS_SHIFT_SUB_HEIGHT, // YV12, I420
128 AVS_CS_SUB_HEIGHT_4 = 1 << AVS_CS_SHIFT_SUB_HEIGHT, // YUV9
129
130 AVS_CS_SAMPLE_BITS_MASK = 7 << AVS_CS_SHIFT_SAMPLE_BITS,
131 AVS_CS_SAMPLE_BITS_8 = 0 << AVS_CS_SHIFT_SAMPLE_BITS,
132 AVS_CS_SAMPLE_BITS_16 = 1 << AVS_CS_SHIFT_SAMPLE_BITS,
133 AVS_CS_SAMPLE_BITS_32 = 2 << AVS_CS_SHIFT_SAMPLE_BITS,
134
135 AVS_CS_PLANAR_MASK = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV | AVS_CS_BGR | AVS_CS_SAMPLE_BITS_MASK | AVS_CS_SUB_HEIGHT_MASK | AVS_CS_SUB_WIDTH_MASK,
136 AVS_CS_PLANAR_FILTER = ~( AVS_CS_VPLANEFIRST | AVS_CS_UPLANEFIRST )};
137
138 // Specific colorformats
139 enum {
140 AVS_CS_UNKNOWN = 0,
141 AVS_CS_BGR24 = 1<<0 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
142 AVS_CS_BGR32 = 1<<1 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
143 AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
144 // AVS_CS_YV12 = 1<<3 Reserved
145 // AVS_CS_I420 = 1<<4 Reserved
146 AVS_CS_RAW32 = 1<<5 | AVS_CS_INTERLEAVED,
147
148 AVS_CS_YV24 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_1, // YVU 4:4:4 planar
149 AVS_CS_YV16 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_2, // YVU 4:2:2 planar
150 AVS_CS_YV12 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2, // YVU 4:2:0 planar
151 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
152 AVS_CS_IYUV = AVS_CS_I420,
153 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
154 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
155 AVS_CS_Y8 = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 // Y 4:0:0 planar
156 };
157
158 enum {
159 AVS_IT_BFF = 1<<0,
160 AVS_IT_TFF = 1<<1,
161 AVS_IT_FIELDBASED = 1<<2};
162
163 enum {
164 AVS_FILTER_TYPE=1,
165 AVS_FILTER_INPUT_COLORSPACE=2,
166 AVS_FILTER_OUTPUT_TYPE=9,
167 AVS_FILTER_NAME=4,
168 AVS_FILTER_AUTHOR=5,
169 AVS_FILTER_VERSION=6,
170 AVS_FILTER_ARGS=7,
171 AVS_FILTER_ARGS_INFO=8,
172 AVS_FILTER_ARGS_DESCRIPTION=10,
173 AVS_FILTER_DESCRIPTION=11};
174
175 enum { //SUBTYPES
176 AVS_FILTER_TYPE_AUDIO=1,
177 AVS_FILTER_TYPE_VIDEO=2,
178 AVS_FILTER_OUTPUT_TYPE_SAME=3,
179 AVS_FILTER_OUTPUT_TYPE_DIFFERENT=4};
180
181 enum {
182 AVS_CACHE_NOTHING=0,
183 AVS_CACHE_RANGE=1,
184 AVS_CACHE_ALL=2,
185 AVS_CACHE_AUDIO=3,
186 AVS_CACHE_AUDIO_NONE=4,
187 AVS_CACHE_AUDIO_AUTO=5
188 };
189
190 #define AVS_FRAME_ALIGN 16
191
192 typedef struct AVS_Clip AVS_Clip;
193 typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
194
195 /////////////////////////////////////////////////////////////////////
196 //
197 // AVS_VideoInfo
198 //
199
200 // AVS_VideoInfo is layed out identicly to VideoInfo
201 typedef struct AVS_VideoInfo {
202 int width, height; // width=0 means no video
203 unsigned fps_numerator, fps_denominator;
204 int num_frames;
205
206 int pixel_type;
207
208 int audio_samples_per_second; // 0 means no audio
209 int sample_type;
210 INT64 num_audio_samples;
211 int nchannels;
212
213 // Imagetype properties
214
215 int image_type;
216 } AVS_VideoInfo;
217
218 // useful functions of the above
avs_has_video(const AVS_VideoInfo * p)219 AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p)
220 { return (p->width!=0); }
221
avs_has_audio(const AVS_VideoInfo * p)222 AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p)
223 { return (p->audio_samples_per_second!=0); }
224
avs_is_rgb(const AVS_VideoInfo * p)225 AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p)
226 { return !!(p->pixel_type&AVS_CS_BGR); }
227
avs_is_rgb24(const AVS_VideoInfo * p)228 AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p)
229 { return (p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24; } // Clear out additional properties
230
avs_is_rgb32(const AVS_VideoInfo * p)231 AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p)
232 { return (p->pixel_type & AVS_CS_BGR32) == AVS_CS_BGR32 ; }
233
avs_is_yuv(const AVS_VideoInfo * p)234 AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p)
235 { return !!(p->pixel_type&AVS_CS_YUV ); }
236
avs_is_yuy2(const AVS_VideoInfo * p)237 AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
238 { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
239
avs_is_yv24(const AVS_VideoInfo * p)240 AVSC_INLINE int avs_is_yv24(const AVS_VideoInfo * p)
241 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV24 & AVS_CS_PLANAR_FILTER); }
242
avs_is_yv16(const AVS_VideoInfo * p)243 AVSC_INLINE int avs_is_yv16(const AVS_VideoInfo * p)
244 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV16 & AVS_CS_PLANAR_FILTER); }
245
avs_is_yv12(const AVS_VideoInfo * p)246 AVSC_INLINE int avs_is_yv12(const AVS_VideoInfo * p)
247 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV12 & AVS_CS_PLANAR_FILTER); }
248
avs_is_yv411(const AVS_VideoInfo * p)249 AVSC_INLINE int avs_is_yv411(const AVS_VideoInfo * p)
250 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV411 & AVS_CS_PLANAR_FILTER); }
251
avs_is_y8(const AVS_VideoInfo * p)252 AVSC_INLINE int avs_is_y8(const AVS_VideoInfo * p)
253 { return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_Y8 & AVS_CS_PLANAR_FILTER); }
254
avs_is_property(const AVS_VideoInfo * p,int property)255 AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
256 { return ((p->pixel_type & property)==property ); }
257
avs_is_planar(const AVS_VideoInfo * p)258 AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
259 { return !!(p->pixel_type & AVS_CS_PLANAR); }
260
avs_is_interleaved(const AVS_VideoInfo * p)261 AVSC_INLINE int avs_is_interleaved(const AVS_VideoInfo * p)
262 { return !!(p->pixel_type & AVS_CS_INTERLEAVED); }
263
avs_is_color_space(const AVS_VideoInfo * p,int c_space)264 AVSC_INLINE int avs_is_color_space(const AVS_VideoInfo * p, int c_space)
265 { return avs_is_planar(p) ? ((p->pixel_type & AVS_CS_PLANAR_MASK) == (c_space & AVS_CS_PLANAR_FILTER)) : ((p->pixel_type & c_space) == c_space); }
266
avs_is_field_based(const AVS_VideoInfo * p)267 AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
268 { return !!(p->image_type & AVS_IT_FIELDBASED); }
269
avs_is_parity_known(const AVS_VideoInfo * p)270 AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
271 { return ((p->image_type & AVS_IT_FIELDBASED)&&(p->image_type & (AVS_IT_BFF | AVS_IT_TFF))); }
272
avs_is_bff(const AVS_VideoInfo * p)273 AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
274 { return !!(p->image_type & AVS_IT_BFF); }
275
avs_is_tff(const AVS_VideoInfo * p)276 AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
277 { return !!(p->image_type & AVS_IT_TFF); }
278
avs_get_field_order(const AVS_VideoInfo * p)279 AVSC_INLINE int avs_get_field_order(const AVS_VideoInfo * p)
280 { return (p->image_type & AVS_IT_BFF) ? AVS_IT_BFF :
281 (p->image_type & AVS_IT_TFF) ? AVS_IT_TFF : 0;}
282
avs_bits_per_pixel(const AVS_VideoInfo * p)283 AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo * p)
284 {
285 switch (p->pixel_type) {
286 case AVS_CS_YV24:
287 case AVS_CS_BGR24: return 24;
288 case AVS_CS_BGR32: return 32;
289 case AVS_CS_YV16:
290 case AVS_CS_YUY2: return 16;
291 case AVS_CS_YV411:
292 case AVS_CS_YV12:
293 case AVS_CS_I420: return 12;
294 case AVS_CS_Y8: return 8;
295 default: return 0;
296 }
297 }
avs_bytes_from_pixels(const AVS_VideoInfo * p,int pixels)298 AVSC_INLINE int avs_bytes_from_pixels(const AVS_VideoInfo * p, int pixels)
299 { return pixels * (avs_bits_per_pixel(p)>>3); } // Will work on planar images, but will return only luma planes
300
avs_row_size(const AVS_VideoInfo * p)301 AVSC_INLINE int avs_row_size(const AVS_VideoInfo * p)
302 { return avs_bytes_from_pixels(p,p->width); } // Also only returns first plane on planar images
303
avs_bmp_size(const AVS_VideoInfo * vi)304 AVSC_INLINE int avs_bmp_size(const AVS_VideoInfo * vi)
305 { if (avs_is_planar(vi)) {int p = vi->height * ((avs_row_size(vi)+3) & ~3); p+=p>>1; return p; } return vi->height * ((avs_row_size(vi)+3) & ~3); }
306
avs_samples_per_second(const AVS_VideoInfo * p)307 AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
308 { return p->audio_samples_per_second; }
309
310
avs_bytes_per_channel_sample(const AVS_VideoInfo * p)311 AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
312 {
313 switch (p->sample_type) {
314 case AVS_SAMPLE_INT8: return sizeof(signed char);
315 case AVS_SAMPLE_INT16: return sizeof(signed short);
316 case AVS_SAMPLE_INT24: return 3;
317 case AVS_SAMPLE_INT32: return sizeof(signed int);
318 case AVS_SAMPLE_FLOAT: return sizeof(float);
319 default: return 0;
320 }
321 }
avs_bytes_per_audio_sample(const AVS_VideoInfo * p)322 AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
323 { return p->nchannels*avs_bytes_per_channel_sample(p);}
324
avs_audio_samples_from_frames(const AVS_VideoInfo * p,INT64 frames)325 AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames)
326 { return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
327
avs_frames_from_audio_samples(const AVS_VideoInfo * p,INT64 samples)328 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
329 { return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); }
330
avs_audio_samples_from_bytes(const AVS_VideoInfo * p,INT64 bytes)331 AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes)
332 { return bytes / avs_bytes_per_audio_sample(p); }
333
avs_bytes_from_audio_samples(const AVS_VideoInfo * p,INT64 samples)334 AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
335 { return samples * avs_bytes_per_audio_sample(p); }
336
avs_audio_channels(const AVS_VideoInfo * p)337 AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
338 { return p->nchannels; }
339
avs_sample_type(const AVS_VideoInfo * p)340 AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
341 { return p->sample_type;}
342
343 // useful mutator
avs_set_property(AVS_VideoInfo * p,int property)344 AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
345 { p->image_type|=property; }
346
avs_clear_property(AVS_VideoInfo * p,int property)347 AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)
348 { p->image_type&=~property; }
349
avs_set_field_based(AVS_VideoInfo * p,int isfieldbased)350 AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)
351 { if (isfieldbased) p->image_type|=AVS_IT_FIELDBASED; else p->image_type&=~AVS_IT_FIELDBASED; }
352
avs_set_fps(AVS_VideoInfo * p,unsigned numerator,unsigned denominator)353 AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator)
354 {
355 unsigned x=numerator, y=denominator;
356 while (y) { // find gcd
357 unsigned t = x%y; x = y; y = t;
358 }
359 p->fps_numerator = numerator/x;
360 p->fps_denominator = denominator/x;
361 }
362
avs_is_same_colorspace(AVS_VideoInfo * x,AVS_VideoInfo * y)363 AVSC_INLINE int avs_is_same_colorspace(AVS_VideoInfo * x, AVS_VideoInfo * y)
364 {
365 return (x->pixel_type == y->pixel_type)
366 || (avs_is_yv12(x) && avs_is_yv12(y));
367 }
368
369 /////////////////////////////////////////////////////////////////////
370 //
371 // AVS_VideoFrame
372 //
373
374 // VideoFrameBuffer holds information about a memory block which is used
375 // for video data. For efficiency, instances of this class are not deleted
376 // when the refcount reaches zero; instead they're stored in a linked list
377 // to be reused. The instances are deleted when the corresponding AVS
378 // file is closed.
379
380 // AVS_VideoFrameBuffer is layed out identicly to VideoFrameBuffer
381 // DO NOT USE THIS STRUCTURE DIRECTLY
382 typedef struct AVS_VideoFrameBuffer {
383 BYTE * data;
384 int data_size;
385 // sequence_number is incremented every time the buffer is changed, so
386 // that stale views can tell they're no longer valid.
387 volatile long sequence_number;
388
389 volatile long refcount;
390 } AVS_VideoFrameBuffer;
391
392 // VideoFrame holds a "window" into a VideoFrameBuffer.
393
394 // AVS_VideoFrame is layed out identicly to IVideoFrame
395 // DO NOT USE THIS STRUCTURE DIRECTLY
396 typedef struct AVS_VideoFrame {
397 volatile long refcount;
398 AVS_VideoFrameBuffer * vfb;
399 int offset, pitch, row_size, height, offsetU, offsetV, pitchUV; // U&V offsets are from top of picture.
400 int row_sizeUV, heightUV;
401 } AVS_VideoFrame;
402
403 // Access functions for AVS_VideoFrame
avs_get_pitch(const AVS_VideoFrame * p)404 AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p) {
405 return p->pitch;}
406
avs_get_pitch_p(const AVS_VideoFrame * p,int plane)407 AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame * p, int plane) {
408 switch (plane) {
409 case AVS_PLANAR_U: case AVS_PLANAR_V: return p->pitchUV;}
410 return p->pitch;}
411
avs_get_row_size(const AVS_VideoFrame * p)412 AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p) {
413 return p->row_size; }
414
avs_get_row_size_p(const AVS_VideoFrame * p,int plane)415 AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame * p, int plane) {
416 int r;
417 switch (plane) {
418 case AVS_PLANAR_U: case AVS_PLANAR_V:
419 if (p->pitchUV) return p->row_sizeUV;
420 else return 0;
421 case AVS_PLANAR_U_ALIGNED: case AVS_PLANAR_V_ALIGNED:
422 if (p->pitchUV) {
423 r = (p->row_sizeUV+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)); // Aligned rowsize
424 if (r < p->pitchUV)
425 return r;
426 return p->row_sizeUV;
427 } else return 0;
428 case AVS_PLANAR_Y_ALIGNED:
429 r = (p->row_size+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)); // Aligned rowsize
430 if (r <= p->pitch)
431 return r;
432 return p->row_size;
433 }
434 return p->row_size;
435 }
436
avs_get_height(const AVS_VideoFrame * p)437 AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p) {
438 return p->height;}
439
avs_get_height_p(const AVS_VideoFrame * p,int plane)440 AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame * p, int plane) {
441 switch (plane) {
442 case AVS_PLANAR_U: case AVS_PLANAR_V:
443 if (p->pitchUV) return p->heightUV;
444 return 0;
445 }
446 return p->height;}
447
avs_get_read_ptr(const AVS_VideoFrame * p)448 AVSC_INLINE const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p) {
449 return p->vfb->data + p->offset;}
450
avs_get_read_ptr_p(const AVS_VideoFrame * p,int plane)451 AVSC_INLINE const BYTE* avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane)
452 {
453 switch (plane) {
454 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
455 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
456 default: return p->vfb->data + p->offset;}
457 }
458
avs_is_writable(const AVS_VideoFrame * p)459 AVSC_INLINE int avs_is_writable(const AVS_VideoFrame * p) {
460 return (p->refcount == 1 && p->vfb->refcount == 1);}
461
avs_get_write_ptr(const AVS_VideoFrame * p)462 AVSC_INLINE BYTE* avs_get_write_ptr(const AVS_VideoFrame * p)
463 {
464 if (avs_is_writable(p)) {
465 ++p->vfb->sequence_number;
466 return p->vfb->data + p->offset;
467 } else
468 return 0;
469 }
470
avs_get_write_ptr_p(const AVS_VideoFrame * p,int plane)471 AVSC_INLINE BYTE* avs_get_write_ptr_p(const AVS_VideoFrame * p, int plane)
472 {
473 if (plane==AVS_PLANAR_Y && avs_is_writable(p)) {
474 ++p->vfb->sequence_number;
475 return p->vfb->data + p->offset;
476 } else if (plane==AVS_PLANAR_Y) {
477 return 0;
478 } else {
479 switch (plane) {
480 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
481 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
482 default: return p->vfb->data + p->offset;
483 }
484 }
485 }
486
487
488 AVSC_API(void, avs_release_video_frame)(AVS_VideoFrame *);
489 // makes a shallow copy of a video frame
490 AVSC_API(AVS_VideoFrame *, avs_copy_video_frame)(AVS_VideoFrame *);
491
492 #ifndef AVSC_NO_DECLSPEC
avs_release_frame(AVS_VideoFrame * f)493 AVSC_INLINE void avs_release_frame(AVS_VideoFrame * f)
494 {avs_release_video_frame(f);}
avs_copy_frame(AVS_VideoFrame * f)495 AVSC_INLINE AVS_VideoFrame * avs_copy_frame(AVS_VideoFrame * f)
496 {return avs_copy_video_frame(f);}
497 #endif
498
499 /////////////////////////////////////////////////////////////////////
500 //
501 // AVS_Value
502 //
503
504 // Treat AVS_Value as a fat pointer. That is use avs_copy_value
505 // and avs_release_value appropiaty as you would if AVS_Value was
506 // a pointer.
507
508 // To maintain source code compatibility with future versions of the
509 // avisynth_c API don't use the AVS_Value directly. Use the helper
510 // functions below.
511
512 // AVS_Value is layed out identicly to AVSValue
513 typedef struct AVS_Value AVS_Value;
514 struct AVS_Value {
515 short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
516 // for some function e'rror
517 short array_size;
518 union {
519 void * clip; // do not use directly, use avs_take_clip
520 char boolean;
521 int integer;
522 float floating_pt;
523 const char * string;
524 const AVS_Value * array;
525 } d;
526 };
527
528 // AVS_Value should be initilized with avs_void.
529 // Should also set to avs_void after the value is released
530 // with avs_copy_value. Consider it the equalvent of setting
531 // a pointer to NULL
532 static const AVS_Value avs_void = {'v'};
533
534 AVSC_API(void, avs_copy_value)(AVS_Value * dest, AVS_Value src);
535 AVSC_API(void, avs_release_value)(AVS_Value);
536
avs_defined(AVS_Value v)537 AVSC_INLINE int avs_defined(AVS_Value v) { return v.type != 'v'; }
avs_is_clip(AVS_Value v)538 AVSC_INLINE int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
avs_is_bool(AVS_Value v)539 AVSC_INLINE int avs_is_bool(AVS_Value v) { return v.type == 'b'; }
avs_is_int(AVS_Value v)540 AVSC_INLINE int avs_is_int(AVS_Value v) { return v.type == 'i'; }
avs_is_float(AVS_Value v)541 AVSC_INLINE int avs_is_float(AVS_Value v) { return v.type == 'f' || v.type == 'i'; }
avs_is_string(AVS_Value v)542 AVSC_INLINE int avs_is_string(AVS_Value v) { return v.type == 's'; }
avs_is_array(AVS_Value v)543 AVSC_INLINE int avs_is_array(AVS_Value v) { return v.type == 'a'; }
avs_is_error(AVS_Value v)544 AVSC_INLINE int avs_is_error(AVS_Value v) { return v.type == 'e'; }
545
546 AVSC_API(AVS_Clip *, avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
547 AVSC_API(void, avs_set_to_clip)(AVS_Value *, AVS_Clip *);
548
avs_as_bool(AVS_Value v)549 AVSC_INLINE int avs_as_bool(AVS_Value v)
550 { return v.d.boolean; }
avs_as_int(AVS_Value v)551 AVSC_INLINE int avs_as_int(AVS_Value v)
552 { return v.d.integer; }
avs_as_string(AVS_Value v)553 AVSC_INLINE const char * avs_as_string(AVS_Value v)
554 { return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
avs_as_float(AVS_Value v)555 AVSC_INLINE double avs_as_float(AVS_Value v)
556 { return avs_is_int(v) ? v.d.integer : v.d.floating_pt; }
avs_as_error(AVS_Value v)557 AVSC_INLINE const char * avs_as_error(AVS_Value v)
558 { return avs_is_error(v) ? v.d.string : 0; }
avs_as_array(AVS_Value v)559 AVSC_INLINE const AVS_Value * avs_as_array(AVS_Value v)
560 { return v.d.array; }
avs_array_size(AVS_Value v)561 AVSC_INLINE int avs_array_size(AVS_Value v)
562 { return avs_is_array(v) ? v.array_size : 1; }
avs_array_elt(AVS_Value v,int index)563 AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index)
564 { return avs_is_array(v) ? v.d.array[index] : v; }
565
566 // only use these functions on an AVS_Value that does not already have
567 // an active value. Remember, treat AVS_Value as a fat pointer.
avs_new_value_bool(int v0)568 AVSC_INLINE AVS_Value avs_new_value_bool(int v0)
569 { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
avs_new_value_int(int v0)570 AVSC_INLINE AVS_Value avs_new_value_int(int v0)
571 { AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }
avs_new_value_string(const char * v0)572 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
573 { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
avs_new_value_float(float v0)574 AVSC_INLINE AVS_Value avs_new_value_float(float v0)
575 { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
avs_new_value_error(const char * v0)576 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
577 { AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
578 #ifndef AVSC_NO_DECLSPEC
avs_new_value_clip(AVS_Clip * v0)579 AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
580 { AVS_Value v; avs_set_to_clip(&v, v0); return v; }
581 #endif
avs_new_value_array(AVS_Value * v0,int size)582 AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
583 { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
584
585 /////////////////////////////////////////////////////////////////////
586 //
587 // AVS_Clip
588 //
589
590 AVSC_API(void, avs_release_clip)(AVS_Clip *);
591 AVSC_API(AVS_Clip *, avs_copy_clip)(AVS_Clip *);
592
593 AVSC_API(const char *, avs_clip_get_error)(AVS_Clip *); // return 0 if no error
594
595 AVSC_API(const AVS_VideoInfo *, avs_get_video_info)(AVS_Clip *);
596
597 AVSC_API(int, avs_get_version)(AVS_Clip *);
598
599 AVSC_API(AVS_VideoFrame *, avs_get_frame)(AVS_Clip *, int n);
600 // The returned video frame must be released with avs_release_video_frame
601
602 AVSC_API(int, avs_get_parity)(AVS_Clip *, int n);
603 // return field parity if field_based, else parity of first field in frame
604
605 AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf,
606 INT64 start, INT64 count);
607 // start and count are in samples
608
609 AVSC_API(int, avs_set_cache_hints)(AVS_Clip *,
610 int cachehints, int frame_range);
611
612 // This is the callback type used by avs_add_function
613 typedef AVS_Value (AVSC_CC * AVS_ApplyFunc)
614 (AVS_ScriptEnvironment *, AVS_Value args, void * user_data);
615
616 typedef struct AVS_FilterInfo AVS_FilterInfo;
617 struct AVS_FilterInfo
618 {
619 // these members should not be modified outside of the AVS_ApplyFunc callback
620 AVS_Clip * child;
621 AVS_VideoInfo vi;
622 AVS_ScriptEnvironment * env;
623 AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n);
624 int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n);
625 int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf,
626 INT64 start, INT64 count);
627 int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints,
628 int frame_range);
629 void (AVSC_CC * free_filter)(AVS_FilterInfo *);
630
631 // Should be set when ever there is an error to report.
632 // It is cleared before any of the above methods are called
633 const char * error;
634 // this is to store whatever and may be modified at will
635 void * user_data;
636 };
637
638 // Create a new filter
639 // fi is set to point to the AVS_FilterInfo so that you can
640 // modify it once it is initilized.
641 // store_child should generally be set to true. If it is not
642 // set than ALL methods (the function pointers) must be defined
643 // If it is set than you do not need to worry about freeing the child
644 // clip.
645 AVSC_API(AVS_Clip *, avs_new_c_filter)(AVS_ScriptEnvironment * e,
646 AVS_FilterInfo * * fi,
647 AVS_Value child, int store_child);
648
649 /////////////////////////////////////////////////////////////////////
650 //
651 // AVS_ScriptEnvironment
652 //
653
654 // For GetCPUFlags. These are backwards-compatible with those in VirtualDub.
655 enum {
656 /* slowest CPU to support extension */
657 AVS_CPU_FORCE = 0x01, // N/A
658 AVS_CPU_FPU = 0x02, // 386/486DX
659 AVS_CPU_MMX = 0x04, // P55C, K6, PII
660 AVS_CPU_INTEGER_SSE = 0x08, // PIII, Athlon
661 AVS_CPU_SSE = 0x10, // PIII, Athlon XP/MP
662 AVS_CPU_SSE2 = 0x20, // PIV, Hammer
663 AVS_CPU_3DNOW = 0x40, // K6-2
664 AVS_CPU_3DNOW_EXT = 0x80, // Athlon
665 AVS_CPU_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2,
666 // which only Hammer will have anyway)
667 AVS_CPUF_SSE3 = 0x100, // PIV+, K8 Venice
668 AVS_CPUF_SSSE3 = 0x200, // Core 2
669 AVS_CPUF_SSE4 = 0x400, // Penryn, Wolfdale, Yorkfield
670 AVS_CPUF_SSE4_1 = 0x400,
671 AVS_CPUF_SSE4_2 = 0x800, // Nehalem
672 };
673
674 AVSC_API(const char *, avs_get_error)(AVS_ScriptEnvironment *); // return 0 if no error
675
676 AVSC_API(long, avs_get_cpu_flags)(AVS_ScriptEnvironment *);
677 AVSC_API(int, avs_check_version)(AVS_ScriptEnvironment *, int version);
678
679 AVSC_API(char *, avs_save_string)(AVS_ScriptEnvironment *, const char* s, int length);
680 AVSC_API(char *, avs_sprintf)(AVS_ScriptEnvironment *, const char * fmt, ...);
681
682 AVSC_API(char *, avs_vsprintf)(AVS_ScriptEnvironment *, const char * fmt, void* val);
683 // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
684
685 AVSC_API(int, avs_add_function)(AVS_ScriptEnvironment *,
686 const char * name, const char * params,
687 AVS_ApplyFunc apply, void * user_data);
688
689 AVSC_API(int, avs_function_exists)(AVS_ScriptEnvironment *, const char * name);
690
691 AVSC_API(AVS_Value, avs_invoke)(AVS_ScriptEnvironment *, const char * name,
692 AVS_Value args, const char** arg_names);
693 // The returned value must be be released with avs_release_value
694
695 AVSC_API(AVS_Value, avs_get_var)(AVS_ScriptEnvironment *, const char* name);
696 // The returned value must be be released with avs_release_value
697
698 AVSC_API(int, avs_set_var)(AVS_ScriptEnvironment *, const char* name, AVS_Value val);
699
700 AVSC_API(int, avs_set_global_var)(AVS_ScriptEnvironment *, const char* name, const AVS_Value val);
701
702 //void avs_push_context(AVS_ScriptEnvironment *, int level=0);
703 //void avs_pop_context(AVS_ScriptEnvironment *);
704
705 AVSC_API(AVS_VideoFrame *, avs_new_video_frame_a)(AVS_ScriptEnvironment *,
706 const AVS_VideoInfo * vi, int align);
707 // align should be at least 16
708
709 #ifndef AVSC_NO_DECLSPEC
710 AVSC_INLINE
avs_new_video_frame(AVS_ScriptEnvironment * env,const AVS_VideoInfo * vi)711 AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
712 const AVS_VideoInfo * vi)
713 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
714
715 AVSC_INLINE
avs_new_frame(AVS_ScriptEnvironment * env,const AVS_VideoInfo * vi)716 AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
717 const AVS_VideoInfo * vi)
718 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
719 #endif
720
721
722 AVSC_API(int, avs_make_writable)(AVS_ScriptEnvironment *, AVS_VideoFrame * * pvf);
723
724 AVSC_API(void, avs_bit_blt)(AVS_ScriptEnvironment *, BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height);
725
726 typedef void (AVSC_CC *AVS_ShutdownFunc)(void* user_data, AVS_ScriptEnvironment * env);
727 AVSC_API(void, avs_at_exit)(AVS_ScriptEnvironment *, AVS_ShutdownFunc function, void * user_data);
728
729 AVSC_API(AVS_VideoFrame *, avs_subframe)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height);
730 // The returned video frame must be be released
731
732 AVSC_API(int, avs_set_memory_max)(AVS_ScriptEnvironment *, int mem);
733
734 AVSC_API(int, avs_set_working_dir)(AVS_ScriptEnvironment *, const char * newdir);
735
736 // avisynth.dll exports this; it's a way to use it as a library, without
737 // writing an AVS script or without going through AVIFile.
738 AVSC_API(AVS_ScriptEnvironment *, avs_create_script_environment)(int version);
739
740 // this symbol is the entry point for the plugin and must
741 // be defined
742 AVSC_EXPORT
743 const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment* env);
744
745
746 AVSC_API(void, avs_delete_script_environment)(AVS_ScriptEnvironment *);
747
748
749 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);
750 // The returned video frame must be be released
751
752 #ifdef AVSC_NO_DECLSPEC
753 // use LoadLibrary and related functions to dynamically load Avisynth instead of declspec(dllimport)
754 /*
755 The following functions needs to have been declared, probably from windows.h
756
757 void* malloc(size_t)
758 void free(void*);
759
760 HMODULE LoadLibrary(const char*);
761 void* GetProcAddress(HMODULE, const char*);
762 FreeLibrary(HMODULE);
763 */
764
765
766 typedef struct AVS_Library AVS_Library;
767
768 #define AVSC_DECLARE_FUNC(name) name##_func name
769
770 struct AVS_Library {
771 HMODULE handle;
772
773 AVSC_DECLARE_FUNC(avs_add_function);
774 AVSC_DECLARE_FUNC(avs_at_exit);
775 AVSC_DECLARE_FUNC(avs_bit_blt);
776 AVSC_DECLARE_FUNC(avs_check_version);
777 AVSC_DECLARE_FUNC(avs_clip_get_error);
778 AVSC_DECLARE_FUNC(avs_copy_clip);
779 AVSC_DECLARE_FUNC(avs_copy_value);
780 AVSC_DECLARE_FUNC(avs_copy_video_frame);
781 AVSC_DECLARE_FUNC(avs_create_script_environment);
782 AVSC_DECLARE_FUNC(avs_delete_script_environment);
783 AVSC_DECLARE_FUNC(avs_function_exists);
784 AVSC_DECLARE_FUNC(avs_get_audio);
785 AVSC_DECLARE_FUNC(avs_get_cpu_flags);
786 AVSC_DECLARE_FUNC(avs_get_error);
787 AVSC_DECLARE_FUNC(avs_get_frame);
788 AVSC_DECLARE_FUNC(avs_get_parity);
789 AVSC_DECLARE_FUNC(avs_get_var);
790 AVSC_DECLARE_FUNC(avs_get_version);
791 AVSC_DECLARE_FUNC(avs_get_video_info);
792 AVSC_DECLARE_FUNC(avs_invoke);
793 AVSC_DECLARE_FUNC(avs_make_writable);
794 AVSC_DECLARE_FUNC(avs_new_c_filter);
795 AVSC_DECLARE_FUNC(avs_new_video_frame_a);
796 AVSC_DECLARE_FUNC(avs_release_clip);
797 AVSC_DECLARE_FUNC(avs_release_value);
798 AVSC_DECLARE_FUNC(avs_release_video_frame);
799 AVSC_DECLARE_FUNC(avs_save_string);
800 AVSC_DECLARE_FUNC(avs_set_cache_hints);
801 AVSC_DECLARE_FUNC(avs_set_global_var);
802 AVSC_DECLARE_FUNC(avs_set_memory_max);
803 AVSC_DECLARE_FUNC(avs_set_to_clip);
804 AVSC_DECLARE_FUNC(avs_set_var);
805 AVSC_DECLARE_FUNC(avs_set_working_dir);
806 AVSC_DECLARE_FUNC(avs_sprintf);
807 AVSC_DECLARE_FUNC(avs_subframe);
808 AVSC_DECLARE_FUNC(avs_subframe_planar);
809 AVSC_DECLARE_FUNC(avs_take_clip);
810 AVSC_DECLARE_FUNC(avs_vsprintf);
811 };
812
813 #undef AVSC_DECLARE_FUNC
814
815
avs_load_library()816 AVSC_INLINE AVS_Library * avs_load_library() {
817 AVS_Library *library = (AVS_Library *)malloc(sizeof(AVS_Library));
818 if (library == NULL)
819 return NULL;
820 library->handle = LoadLibrary("avisynth");
821 if (library->handle == NULL)
822 goto fail;
823
824 #define __AVSC_STRINGIFY(x) #x
825 #define AVSC_STRINGIFY(x) __AVSC_STRINGIFY(x)
826 #define AVSC_LOAD_FUNC(name) {\
827 library->name = (name##_func) GetProcAddress(library->handle, AVSC_STRINGIFY(name));\
828 if (library->name == NULL)\
829 goto fail;\
830 }
831
832 AVSC_LOAD_FUNC(avs_add_function);
833 AVSC_LOAD_FUNC(avs_at_exit);
834 AVSC_LOAD_FUNC(avs_bit_blt);
835 AVSC_LOAD_FUNC(avs_check_version);
836 AVSC_LOAD_FUNC(avs_clip_get_error);
837 AVSC_LOAD_FUNC(avs_copy_clip);
838 AVSC_LOAD_FUNC(avs_copy_value);
839 AVSC_LOAD_FUNC(avs_copy_video_frame);
840 AVSC_LOAD_FUNC(avs_create_script_environment);
841 AVSC_LOAD_FUNC(avs_delete_script_environment);
842 AVSC_LOAD_FUNC(avs_function_exists);
843 AVSC_LOAD_FUNC(avs_get_audio);
844 AVSC_LOAD_FUNC(avs_get_cpu_flags);
845 AVSC_LOAD_FUNC(avs_get_error);
846 AVSC_LOAD_FUNC(avs_get_frame);
847 AVSC_LOAD_FUNC(avs_get_parity);
848 AVSC_LOAD_FUNC(avs_get_var);
849 AVSC_LOAD_FUNC(avs_get_version);
850 AVSC_LOAD_FUNC(avs_get_video_info);
851 AVSC_LOAD_FUNC(avs_invoke);
852 AVSC_LOAD_FUNC(avs_make_writable);
853 AVSC_LOAD_FUNC(avs_new_c_filter);
854 AVSC_LOAD_FUNC(avs_new_video_frame_a);
855 AVSC_LOAD_FUNC(avs_release_clip);
856 AVSC_LOAD_FUNC(avs_release_value);
857 AVSC_LOAD_FUNC(avs_release_video_frame);
858 AVSC_LOAD_FUNC(avs_save_string);
859 AVSC_LOAD_FUNC(avs_set_cache_hints);
860 AVSC_LOAD_FUNC(avs_set_global_var);
861 AVSC_LOAD_FUNC(avs_set_memory_max);
862 AVSC_LOAD_FUNC(avs_set_to_clip);
863 AVSC_LOAD_FUNC(avs_set_var);
864 AVSC_LOAD_FUNC(avs_set_working_dir);
865 AVSC_LOAD_FUNC(avs_sprintf);
866 AVSC_LOAD_FUNC(avs_subframe);
867 AVSC_LOAD_FUNC(avs_subframe_planar);
868 AVSC_LOAD_FUNC(avs_take_clip);
869 AVSC_LOAD_FUNC(avs_vsprintf);
870
871 #undef __AVSC_STRINGIFY
872 #undef AVSC_STRINGIFY
873 #undef AVSC_LOAD_FUNC
874
875 return library;
876
877 fail:
878 free(library);
879 return NULL;
880 }
881
avs_free_library(AVS_Library * library)882 AVSC_INLINE void avs_free_library(AVS_Library *library) {
883 if (library == NULL)
884 return;
885 FreeLibrary(library->handle);
886 free(library);
887 }
888 #endif
889
890 #endif
891