avisynth_c.h 42 KB

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