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 #ifndef __AVXSYNTH_C__
34 #define __AVXSYNTH_C__
35
36 #include <stdarg.h>
37 #include <stdint.h>
38
39 typedef int64_t INT64;
40 #define __stdcall
41 #define __declspec(x)
42
43 #ifdef __cplusplus
44 # define EXTERN_C extern "C"
45 #else
46 # define EXTERN_C
47 #endif
48
49 #define AVSC_USE_STDCALL 1
50
51 #ifndef AVSC_USE_STDCALL
52 # define AVSC_CC __cdecl
53 #else
54 # define AVSC_CC __stdcall
55 #endif
56
57 #define AVSC_INLINE static __inline
58
59 #ifdef AVISYNTH_C_EXPORTS
60 # define AVSC_EXPORT EXTERN_C
61 # define AVSC_API(ret, name) EXTERN_C __declspec(dllexport) ret AVSC_CC name
62 #else
63 # define AVSC_EXPORT EXTERN_C __declspec(dllexport)
64 # ifndef AVSC_NO_DECLSPEC
65 # define AVSC_API(ret, name) EXTERN_C __declspec(dllimport) ret AVSC_CC name
66 # else
67 # define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func)
68 # endif
69 #endif
70
71
72 /////////////////////////////////////////////////////////////////////
73 //
74 // Constants
75 //
76
77 #ifndef __AVXSYNTH_H__
78 enum { AVISYNTH_INTERFACE_VERSION = 3 };
79 #endif
80
81 enum {AVS_SAMPLE_INT8 = 1<<0,
82 AVS_SAMPLE_INT16 = 1<<1,
83 AVS_SAMPLE_INT24 = 1<<2,
84 AVS_SAMPLE_INT32 = 1<<3,
85 AVS_SAMPLE_FLOAT = 1<<4};
86
87 enum {AVS_PLANAR_Y=1<<0,
88 AVS_PLANAR_U=1<<1,
89 AVS_PLANAR_V=1<<2,
90 AVS_PLANAR_ALIGNED=1<<3,
91 AVS_PLANAR_Y_ALIGNED=AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
92 AVS_PLANAR_U_ALIGNED=AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
93 AVS_PLANAR_V_ALIGNED=AVS_PLANAR_V|AVS_PLANAR_ALIGNED};
94
95 // Colorspace properties.
96 enum {AVS_CS_BGR = 1<<28,
97 AVS_CS_YUV = 1<<29,
98 AVS_CS_INTERLEAVED = 1<<30,
99 AVS_CS_PLANAR = 1<<31};
100
101 // Specific colorformats
102 enum {
103 AVS_CS_UNKNOWN = 0,
104 AVS_CS_BGR24 = 1<<0 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
105 AVS_CS_BGR32 = 1<<1 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
106 AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
107 AVS_CS_YV12 = 1<<3 | AVS_CS_YUV | AVS_CS_PLANAR, // y-v-u, planar
108 AVS_CS_I420 = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR, // y-u-v, planar
109 AVS_CS_IYUV = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR // same as above
110 };
111
112 enum {
113 AVS_IT_BFF = 1<<0,
114 AVS_IT_TFF = 1<<1,
115 AVS_IT_FIELDBASED = 1<<2};
116
117 enum {
118 AVS_FILTER_TYPE=1,
119 AVS_FILTER_INPUT_COLORSPACE=2,
120 AVS_FILTER_OUTPUT_TYPE=9,
121 AVS_FILTER_NAME=4,
122 AVS_FILTER_AUTHOR=5,
123 AVS_FILTER_VERSION=6,
124 AVS_FILTER_ARGS=7,
125 AVS_FILTER_ARGS_INFO=8,
126 AVS_FILTER_ARGS_DESCRIPTION=10,
127 AVS_FILTER_DESCRIPTION=11};
128
129 enum { //SUBTYPES
130 AVS_FILTER_TYPE_AUDIO=1,
131 AVS_FILTER_TYPE_VIDEO=2,
132 AVS_FILTER_OUTPUT_TYPE_SAME=3,
133 AVS_FILTER_OUTPUT_TYPE_DIFFERENT=4};
134
135 enum {
136 AVS_CACHE_NOTHING=0,
137 AVS_CACHE_RANGE=1,
138 AVS_CACHE_ALL=2,
139 AVS_CACHE_AUDIO=3,
140 AVS_CACHE_AUDIO_NONE=4,
141 AVS_CACHE_AUDIO_AUTO=5
142 };
143
144 #define AVS_FRAME_ALIGN 16
145
146 typedef struct AVS_Clip AVS_Clip;
147 typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
148
149 /////////////////////////////////////////////////////////////////////
150 //
151 // AVS_VideoInfo
152 //
153
154 // AVS_VideoInfo is layed out identicly to VideoInfo
155 typedef struct AVS_VideoInfo {
156 int width, height; // width=0 means no video
157 unsigned fps_numerator, fps_denominator;
158 int num_frames;
159
160 int pixel_type;
161
162 int audio_samples_per_second; // 0 means no audio
163 int sample_type;
164 INT64 num_audio_samples;
165 int nchannels;
166
167 // Imagetype properties
168
169 int image_type;
170 } AVS_VideoInfo;
171
172 // useful functions of the above
avs_has_video(const AVS_VideoInfo * p)173 AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p)
174 { return (p->width!=0); }
175
avs_has_audio(const AVS_VideoInfo * p)176 AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p)
177 { return (p->audio_samples_per_second!=0); }
178
avs_is_rgb(const AVS_VideoInfo * p)179 AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p)
180 { return !!(p->pixel_type&AVS_CS_BGR); }
181
avs_is_rgb24(const AVS_VideoInfo * p)182 AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p)
183 { return (p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24; } // Clear out additional properties
184
avs_is_rgb32(const AVS_VideoInfo * p)185 AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p)
186 { return (p->pixel_type & AVS_CS_BGR32) == AVS_CS_BGR32 ; }
187
avs_is_yuv(const AVS_VideoInfo * p)188 AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p)
189 { return !!(p->pixel_type&AVS_CS_YUV ); }
190
avs_is_yuy2(const AVS_VideoInfo * p)191 AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
192 { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
193
avs_is_yv12(const AVS_VideoInfo * p)194 AVSC_INLINE int avs_is_yv12(const AVS_VideoInfo * p)
195 { return ((p->pixel_type & AVS_CS_YV12) == AVS_CS_YV12)||((p->pixel_type & AVS_CS_I420) == AVS_CS_I420); }
196
avs_is_color_space(const AVS_VideoInfo * p,int c_space)197 AVSC_INLINE int avs_is_color_space(const AVS_VideoInfo * p, int c_space)
198 { return ((p->pixel_type & c_space) == c_space); }
199
avs_is_property(const AVS_VideoInfo * p,int property)200 AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
201 { return ((p->pixel_type & property)==property ); }
202
avs_is_planar(const AVS_VideoInfo * p)203 AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
204 { return !!(p->pixel_type & AVS_CS_PLANAR); }
205
avs_is_field_based(const AVS_VideoInfo * p)206 AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
207 { return !!(p->image_type & AVS_IT_FIELDBASED); }
208
avs_is_parity_known(const AVS_VideoInfo * p)209 AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
210 { return ((p->image_type & AVS_IT_FIELDBASED)&&(p->image_type & (AVS_IT_BFF | AVS_IT_TFF))); }
211
avs_is_bff(const AVS_VideoInfo * p)212 AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
213 { return !!(p->image_type & AVS_IT_BFF); }
214
avs_is_tff(const AVS_VideoInfo * p)215 AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
216 { return !!(p->image_type & AVS_IT_TFF); }
217
avs_bits_per_pixel(const AVS_VideoInfo * p)218 AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo * p)
219 {
220 switch (p->pixel_type) {
221 case AVS_CS_BGR24: return 24;
222 case AVS_CS_BGR32: return 32;
223 case AVS_CS_YUY2: return 16;
224 case AVS_CS_YV12:
225 case AVS_CS_I420: return 12;
226 default: return 0;
227 }
228 }
avs_bytes_from_pixels(const AVS_VideoInfo * p,int pixels)229 AVSC_INLINE int avs_bytes_from_pixels(const AVS_VideoInfo * p, int pixels)
230 { return pixels * (avs_bits_per_pixel(p)>>3); } // Will work on planar images, but will return only luma planes
231
avs_row_size(const AVS_VideoInfo * p)232 AVSC_INLINE int avs_row_size(const AVS_VideoInfo * p)
233 { return avs_bytes_from_pixels(p,p->width); } // Also only returns first plane on planar images
234
avs_bmp_size(const AVS_VideoInfo * vi)235 AVSC_INLINE int avs_bmp_size(const AVS_VideoInfo * vi)
236 { 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); }
237
avs_samples_per_second(const AVS_VideoInfo * p)238 AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
239 { return p->audio_samples_per_second; }
240
241
avs_bytes_per_channel_sample(const AVS_VideoInfo * p)242 AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
243 {
244 switch (p->sample_type) {
245 case AVS_SAMPLE_INT8: return sizeof(signed char);
246 case AVS_SAMPLE_INT16: return sizeof(signed short);
247 case AVS_SAMPLE_INT24: return 3;
248 case AVS_SAMPLE_INT32: return sizeof(signed int);
249 case AVS_SAMPLE_FLOAT: return sizeof(float);
250 default: return 0;
251 }
252 }
avs_bytes_per_audio_sample(const AVS_VideoInfo * p)253 AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
254 { return p->nchannels*avs_bytes_per_channel_sample(p);}
255
avs_audio_samples_from_frames(const AVS_VideoInfo * p,INT64 frames)256 AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames)
257 { return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
258
avs_frames_from_audio_samples(const AVS_VideoInfo * p,INT64 samples)259 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
260 { return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); }
261
avs_audio_samples_from_bytes(const AVS_VideoInfo * p,INT64 bytes)262 AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes)
263 { return bytes / avs_bytes_per_audio_sample(p); }
264
avs_bytes_from_audio_samples(const AVS_VideoInfo * p,INT64 samples)265 AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
266 { return samples * avs_bytes_per_audio_sample(p); }
267
avs_audio_channels(const AVS_VideoInfo * p)268 AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
269 { return p->nchannels; }
270
avs_sample_type(const AVS_VideoInfo * p)271 AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
272 { return p->sample_type;}
273
274 // useful mutator
avs_set_property(AVS_VideoInfo * p,int property)275 AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
276 { p->image_type|=property; }
277
avs_clear_property(AVS_VideoInfo * p,int property)278 AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)
279 { p->image_type&=~property; }
280
avs_set_field_based(AVS_VideoInfo * p,int isfieldbased)281 AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)
282 { if (isfieldbased) p->image_type|=AVS_IT_FIELDBASED; else p->image_type&=~AVS_IT_FIELDBASED; }
283
avs_set_fps(AVS_VideoInfo * p,unsigned numerator,unsigned denominator)284 AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator)
285 {
286 unsigned x=numerator, y=denominator;
287 while (y) { // find gcd
288 unsigned t = x%y; x = y; y = t;
289 }
290 p->fps_numerator = numerator/x;
291 p->fps_denominator = denominator/x;
292 }
293
avs_is_same_colorspace(AVS_VideoInfo * x,AVS_VideoInfo * y)294 AVSC_INLINE int avs_is_same_colorspace(AVS_VideoInfo * x, AVS_VideoInfo * y)
295 {
296 return (x->pixel_type == y->pixel_type)
297 || (avs_is_yv12(x) && avs_is_yv12(y));
298 }
299
300 /////////////////////////////////////////////////////////////////////
301 //
302 // AVS_VideoFrame
303 //
304
305 // VideoFrameBuffer holds information about a memory block which is used
306 // for video data. For efficiency, instances of this class are not deleted
307 // when the refcount reaches zero; instead they're stored in a linked list
308 // to be reused. The instances are deleted when the corresponding AVS
309 // file is closed.
310
311 // AVS_VideoFrameBuffer is layed out identicly to VideoFrameBuffer
312 // DO NOT USE THIS STRUCTURE DIRECTLY
313 typedef struct AVS_VideoFrameBuffer {
314 unsigned char * data;
315 int data_size;
316 // sequence_number is incremented every time the buffer is changed, so
317 // that stale views can tell they're no longer valid.
318 long sequence_number;
319
320 long refcount;
321 } AVS_VideoFrameBuffer;
322
323 // VideoFrame holds a "window" into a VideoFrameBuffer.
324
325 // AVS_VideoFrame is layed out identicly to IVideoFrame
326 // DO NOT USE THIS STRUCTURE DIRECTLY
327 typedef struct AVS_VideoFrame {
328 int refcount;
329 AVS_VideoFrameBuffer * vfb;
330 int offset, pitch, row_size, height, offsetU, offsetV, pitchUV; // U&V offsets are from top of picture.
331 } AVS_VideoFrame;
332
333 // Access functions for AVS_VideoFrame
avs_get_pitch(const AVS_VideoFrame * p)334 AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p) {
335 return p->pitch;}
336
avs_get_pitch_p(const AVS_VideoFrame * p,int plane)337 AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame * p, int plane) {
338 switch (plane) {
339 case AVS_PLANAR_U: case AVS_PLANAR_V: return p->pitchUV;}
340 return p->pitch;}
341
avs_get_row_size(const AVS_VideoFrame * p)342 AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p) {
343 return p->row_size; }
344
avs_get_row_size_p(const AVS_VideoFrame * p,int plane)345 AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame * p, int plane) {
346 int r;
347 switch (plane) {
348 case AVS_PLANAR_U: case AVS_PLANAR_V:
349 if (p->pitchUV) return p->row_size>>1;
350 else return 0;
351 case AVS_PLANAR_U_ALIGNED: case AVS_PLANAR_V_ALIGNED:
352 if (p->pitchUV) {
353 r = ((p->row_size+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)) )>>1; // Aligned rowsize
354 if (r < p->pitchUV)
355 return r;
356 return p->row_size>>1;
357 } else return 0;
358 case AVS_PLANAR_Y_ALIGNED:
359 r = (p->row_size+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)); // Aligned rowsize
360 if (r <= p->pitch)
361 return r;
362 return p->row_size;
363 }
364 return p->row_size;
365 }
366
avs_get_height(const AVS_VideoFrame * p)367 AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p) {
368 return p->height;}
369
avs_get_height_p(const AVS_VideoFrame * p,int plane)370 AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame * p, int plane) {
371 switch (plane) {
372 case AVS_PLANAR_U: case AVS_PLANAR_V:
373 if (p->pitchUV) return p->height>>1;
374 return 0;
375 }
376 return p->height;}
377
avs_get_read_ptr(const AVS_VideoFrame * p)378 AVSC_INLINE const unsigned char* avs_get_read_ptr(const AVS_VideoFrame * p) {
379 return p->vfb->data + p->offset;}
380
avs_get_read_ptr_p(const AVS_VideoFrame * p,int plane)381 AVSC_INLINE const unsigned char* avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane)
382 {
383 switch (plane) {
384 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
385 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
386 default: return p->vfb->data + p->offset;}
387 }
388
avs_is_writable(const AVS_VideoFrame * p)389 AVSC_INLINE int avs_is_writable(const AVS_VideoFrame * p) {
390 return (p->refcount == 1 && p->vfb->refcount == 1);}
391
avs_get_write_ptr(const AVS_VideoFrame * p)392 AVSC_INLINE unsigned char* avs_get_write_ptr(const AVS_VideoFrame * p)
393 {
394 if (avs_is_writable(p)) {
395 ++p->vfb->sequence_number;
396 return p->vfb->data + p->offset;
397 } else
398 return 0;
399 }
400
avs_get_write_ptr_p(const AVS_VideoFrame * p,int plane)401 AVSC_INLINE unsigned char* avs_get_write_ptr_p(const AVS_VideoFrame * p, int plane)
402 {
403 if (plane==AVS_PLANAR_Y && avs_is_writable(p)) {
404 ++p->vfb->sequence_number;
405 return p->vfb->data + p->offset;
406 } else if (plane==AVS_PLANAR_Y) {
407 return 0;
408 } else {
409 switch (plane) {
410 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
411 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
412 default: return p->vfb->data + p->offset;
413 }
414 }
415 }
416
417 #if defined __cplusplus
418 extern "C"
419 {
420 #endif // __cplusplus
421 AVSC_API(void, avs_release_video_frame)(AVS_VideoFrame *);
422 // makes a shallow copy of a video frame
423 AVSC_API(AVS_VideoFrame *, avs_copy_video_frame)(AVS_VideoFrame *);
424 #if defined __cplusplus
425 }
426 #endif // __cplusplus
427
428 #ifndef AVSC_NO_DECLSPEC
avs_release_frame(AVS_VideoFrame * f)429 AVSC_INLINE void avs_release_frame(AVS_VideoFrame * f)
430 {avs_release_video_frame(f);}
avs_copy_frame(AVS_VideoFrame * f)431 AVSC_INLINE AVS_VideoFrame * avs_copy_frame(AVS_VideoFrame * f)
432 {return avs_copy_video_frame(f);}
433 #endif
434
435 /////////////////////////////////////////////////////////////////////
436 //
437 // AVS_Value
438 //
439
440 // Treat AVS_Value as a fat pointer. That is use avs_copy_value
441 // and avs_release_value appropiaty as you would if AVS_Value was
442 // a pointer.
443
444 // To maintain source code compatibility with future versions of the
445 // avisynth_c API don't use the AVS_Value directly. Use the helper
446 // functions below.
447
448 // AVS_Value is layed out identicly to AVSValue
449 typedef struct AVS_Value AVS_Value;
450 struct AVS_Value {
451 short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
452 // for some function e'rror
453 short array_size;
454 union {
455 void * clip; // do not use directly, use avs_take_clip
456 char boolean;
457 int integer;
458 INT64 integer64; // match addition of __int64 to avxplugin.h
459 float floating_pt;
460 const char * string;
461 const AVS_Value * array;
462 } d;
463 };
464
465 // AVS_Value should be initilized with avs_void.
466 // Should also set to avs_void after the value is released
467 // with avs_copy_value. Consider it the equalvent of setting
468 // a pointer to NULL
469 static const AVS_Value avs_void = {'v'};
470
471 AVSC_API(void, avs_copy_value)(AVS_Value * dest, AVS_Value src);
472 AVSC_API(void, avs_release_value)(AVS_Value);
473
avs_defined(AVS_Value v)474 AVSC_INLINE int avs_defined(AVS_Value v) { return v.type != 'v'; }
avs_is_clip(AVS_Value v)475 AVSC_INLINE int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
avs_is_bool(AVS_Value v)476 AVSC_INLINE int avs_is_bool(AVS_Value v) { return v.type == 'b'; }
avs_is_int(AVS_Value v)477 AVSC_INLINE int avs_is_int(AVS_Value v) { return v.type == 'i'; }
avs_is_float(AVS_Value v)478 AVSC_INLINE int avs_is_float(AVS_Value v) { return v.type == 'f' || v.type == 'i'; }
avs_is_string(AVS_Value v)479 AVSC_INLINE int avs_is_string(AVS_Value v) { return v.type == 's'; }
avs_is_array(AVS_Value v)480 AVSC_INLINE int avs_is_array(AVS_Value v) { return v.type == 'a'; }
avs_is_error(AVS_Value v)481 AVSC_INLINE int avs_is_error(AVS_Value v) { return v.type == 'e'; }
482
483 #if defined __cplusplus
484 extern "C"
485 {
486 #endif // __cplusplus
487 AVSC_API(AVS_Clip *, avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
488 AVSC_API(void, avs_set_to_clip)(AVS_Value *, AVS_Clip *);
489 #if defined __cplusplus
490 }
491 #endif // __cplusplus
492
avs_as_bool(AVS_Value v)493 AVSC_INLINE int avs_as_bool(AVS_Value v)
494 { return v.d.boolean; }
avs_as_int(AVS_Value v)495 AVSC_INLINE int avs_as_int(AVS_Value v)
496 { return v.d.integer; }
avs_as_string(AVS_Value v)497 AVSC_INLINE const char * avs_as_string(AVS_Value v)
498 { return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
avs_as_float(AVS_Value v)499 AVSC_INLINE double avs_as_float(AVS_Value v)
500 { return avs_is_int(v) ? v.d.integer : v.d.floating_pt; }
avs_as_error(AVS_Value v)501 AVSC_INLINE const char * avs_as_error(AVS_Value v)
502 { return avs_is_error(v) ? v.d.string : 0; }
avs_as_array(AVS_Value v)503 AVSC_INLINE const AVS_Value * avs_as_array(AVS_Value v)
504 { return v.d.array; }
avs_array_size(AVS_Value v)505 AVSC_INLINE int avs_array_size(AVS_Value v)
506 { return avs_is_array(v) ? v.array_size : 1; }
avs_array_elt(AVS_Value v,int index)507 AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index)
508 { return avs_is_array(v) ? v.d.array[index] : v; }
509
510 // only use these functions on am AVS_Value that does not already have
511 // an active value. Remember, treat AVS_Value as a fat pointer.
avs_new_value_bool(int v0)512 AVSC_INLINE AVS_Value avs_new_value_bool(int v0)
513 { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
avs_new_value_int(int v0)514 AVSC_INLINE AVS_Value avs_new_value_int(int v0)
515 { AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }
avs_new_value_string(const char * v0)516 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
517 { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
avs_new_value_float(float v0)518 AVSC_INLINE AVS_Value avs_new_value_float(float v0)
519 { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
avs_new_value_error(const char * v0)520 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
521 { AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
522 #ifndef AVSC_NO_DECLSPEC
avs_new_value_clip(AVS_Clip * v0)523 AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
524 { AVS_Value v; avs_set_to_clip(&v, v0); return v; }
525 #endif
avs_new_value_array(AVS_Value * v0,int size)526 AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
527 { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
528
529 /////////////////////////////////////////////////////////////////////
530 //
531 // AVS_Clip
532 //
533 #if defined __cplusplus
534 extern "C"
535 {
536 #endif // __cplusplus
537 AVSC_API(void, avs_release_clip)(AVS_Clip *);
538 AVSC_API(AVS_Clip *, avs_copy_clip)(AVS_Clip *);
539
540 AVSC_API(const char *, avs_clip_get_error)(AVS_Clip *); // return 0 if no error
541
542 AVSC_API(const AVS_VideoInfo *, avs_get_video_info)(AVS_Clip *);
543
544 AVSC_API(int, avs_get_version)(AVS_Clip *);
545
546 AVSC_API(AVS_VideoFrame *, avs_get_frame)(AVS_Clip *, int n);
547 // The returned video frame must be released with avs_release_video_frame
548
549 AVSC_API(int, avs_get_parity)(AVS_Clip *, int n);
550 // return field parity if field_based, else parity of first field in frame
551
552 AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf,
553 INT64 start, INT64 count);
554 // start and count are in samples
555
556 AVSC_API(int, avs_set_cache_hints)(AVS_Clip *,
557 int cachehints, size_t frame_range);
558 #if defined __cplusplus
559 }
560 #endif // __cplusplus
561
562 // This is the callback type used by avs_add_function
563 typedef AVS_Value (AVSC_CC * AVS_ApplyFunc)
564 (AVS_ScriptEnvironment *, AVS_Value args, void * user_data);
565
566 typedef struct AVS_FilterInfo AVS_FilterInfo;
567 struct AVS_FilterInfo
568 {
569 // these members should not be modified outside of the AVS_ApplyFunc callback
570 AVS_Clip * child;
571 AVS_VideoInfo vi;
572 AVS_ScriptEnvironment * env;
573 AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n);
574 int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n);
575 int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf,
576 INT64 start, INT64 count);
577 int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints,
578 int frame_range);
579 void (AVSC_CC * free_filter)(AVS_FilterInfo *);
580
581 // Should be set when ever there is an error to report.
582 // It is cleared before any of the above methods are called
583 const char * error;
584 // this is to store whatever and may be modified at will
585 void * user_data;
586 };
587
588 // Create a new filter
589 // fi is set to point to the AVS_FilterInfo so that you can
590 // modify it once it is initilized.
591 // store_child should generally be set to true. If it is not
592 // set than ALL methods (the function pointers) must be defined
593 // If it is set than you do not need to worry about freeing the child
594 // clip.
595 #if defined __cplusplus
596 extern "C"
597 {
598 #endif // __cplusplus
599 AVSC_API(AVS_Clip *, avs_new_c_filter)(AVS_ScriptEnvironment * e,
600 AVS_FilterInfo * * fi,
601 AVS_Value child, int store_child);
602 #if defined __cplusplus
603 }
604 #endif // __cplusplus
605
606
607 /////////////////////////////////////////////////////////////////////
608 //
609 // AVS_ScriptEnvironment
610 //
611
612 // For GetCPUFlags. These are backwards-compatible with those in VirtualDub.
613 enum {
614 /* slowest CPU to support extension */
615 AVS_CPU_FORCE = 0x01, // N/A
616 AVS_CPU_FPU = 0x02, // 386/486DX
617 AVS_CPU_MMX = 0x04, // P55C, K6, PII
618 AVS_CPU_INTEGER_SSE = 0x08, // PIII, Athlon
619 AVS_CPU_SSE = 0x10, // PIII, Athlon XP/MP
620 AVS_CPU_SSE2 = 0x20, // PIV, Hammer
621 AVS_CPU_3DNOW = 0x40, // K6-2
622 AVS_CPU_3DNOW_EXT = 0x80, // Athlon
623 AVS_CPU_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2,
624 // which only Hammer will have anyway)
625 };
626
627 #if defined __cplusplus
628 extern "C"
629 {
630 #endif // __cplusplus
631 AVSC_API(const char *, avs_get_error)(AVS_ScriptEnvironment *); // return 0 if no error
632
633 AVSC_API(long, avs_get_cpu_flags)(AVS_ScriptEnvironment *);
634 AVSC_API(int, avs_check_version)(AVS_ScriptEnvironment *, int version);
635
636 AVSC_API(char *, avs_save_string)(AVS_ScriptEnvironment *, const char* s, int length);
637 AVSC_API(char *, avs_sprintf)(AVS_ScriptEnvironment *, const char * fmt, ...);
638
639 AVSC_API(char *, avs_vsprintf)(AVS_ScriptEnvironment *, const char * fmt, va_list val);
640 // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
641
642 AVSC_API(int, avs_add_function)(AVS_ScriptEnvironment *,
643 const char * name, const char * params,
644 AVS_ApplyFunc apply, void * user_data);
645
646 AVSC_API(int, avs_function_exists)(AVS_ScriptEnvironment *, const char * name);
647
648 AVSC_API(AVS_Value, avs_invoke)(AVS_ScriptEnvironment *, const char * name,
649 AVS_Value args, const char** arg_names);
650 // The returned value must be be released with avs_release_value
651
652 AVSC_API(AVS_Value, avs_get_var)(AVS_ScriptEnvironment *, const char* name);
653 // The returned value must be be released with avs_release_value
654
655 AVSC_API(int, avs_set_var)(AVS_ScriptEnvironment *, const char* name, AVS_Value val);
656
657 AVSC_API(int, avs_set_global_var)(AVS_ScriptEnvironment *, const char* name, const AVS_Value val);
658
659 //void avs_push_context(AVS_ScriptEnvironment *, int level=0);
660 //void avs_pop_context(AVS_ScriptEnvironment *);
661
662 AVSC_API(AVS_VideoFrame *, avs_new_video_frame_a)(AVS_ScriptEnvironment *,
663 const AVS_VideoInfo * vi, int align);
664 // align should be at least 16
665 #if defined __cplusplus
666 }
667 #endif // __cplusplus
668
669 #ifndef AVSC_NO_DECLSPEC
670 AVSC_INLINE
avs_new_video_frame(AVS_ScriptEnvironment * env,const AVS_VideoInfo * vi)671 AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
672 const AVS_VideoInfo * vi)
673 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
674
675 AVSC_INLINE
avs_new_frame(AVS_ScriptEnvironment * env,const AVS_VideoInfo * vi)676 AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
677 const AVS_VideoInfo * vi)
678 {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
679 #endif
680
681 #if defined __cplusplus
682 extern "C"
683 {
684 #endif // __cplusplus
685 AVSC_API(int, avs_make_writable)(AVS_ScriptEnvironment *, AVS_VideoFrame * * pvf);
686
687 AVSC_API(void, avs_bit_blt)(AVS_ScriptEnvironment *, unsigned char* dstp, int dst_pitch, const unsigned char* srcp, int src_pitch, int row_size, int height);
688
689 typedef void (AVSC_CC *AVS_ShutdownFunc)(void* user_data, AVS_ScriptEnvironment * env);
690 AVSC_API(void, avs_at_exit)(AVS_ScriptEnvironment *, AVS_ShutdownFunc function, void * user_data);
691
692 AVSC_API(AVS_VideoFrame *, avs_subframe)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height);
693 // The returned video frame must be be released
694
695 AVSC_API(int, avs_set_memory_max)(AVS_ScriptEnvironment *, int mem);
696
697 AVSC_API(int, avs_set_working_dir)(AVS_ScriptEnvironment *, const char * newdir);
698
699 // avisynth.dll exports this; it's a way to use it as a library, without
700 // writing an AVS script or without going through AVIFile.
701 AVSC_API(AVS_ScriptEnvironment *, avs_create_script_environment)(int version);
702 #if defined __cplusplus
703 }
704 #endif // __cplusplus
705
706 // this symbol is the entry point for the plugin and must
707 // be defined
708 AVSC_EXPORT
709 const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment* env);
710
711
712 #if defined __cplusplus
713 extern "C"
714 {
715 #endif // __cplusplus
716 AVSC_API(void, avs_delete_script_environment)(AVS_ScriptEnvironment *);
717
718
719 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);
720 // The returned video frame must be be released
721 #if defined __cplusplus
722 }
723 #endif // __cplusplus
724
725 #endif //__AVXSYNTH_C__
726