avxsynth_c.h 26 KB

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