forked from gispos/AvsPmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavisynth_cffi.py
2122 lines (1778 loc) · 83.8 KB
/
avisynth_cffi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# avisynth - Python AviSynth wrapper
#
# Copyright 2013, 2016, 2019 the AvsPmod authors <https://github.com/avspmod/avspmod>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
# http://www.gnu.org/copyleft/gpl.html .
# Dependencies:
# Python (tested on v2.7)
# cffi and its dependencies (tested on v0.8.1)
# pycparser
# Visual Studio 2008
# avisynth_c.h (interface 6, AVS+, now part of the project)
# Optional:
# global_vars.py (for specifying a custom shared library location)
#
# Notes:
#
# These bindings are NOT compatible with AVISYNTH_INTERFACE_VERSION 3.
#
# Define/undef AVSC_USE_STDCALL on the verify string as needed.
#
# libffi doesn't support passing structs or unions with bit-fields by value.
# To circunvent this some C wrappers were written for the affected functions.
# This implies compiling a C extension (auto-generated by cffi).
#
# The bindings uses LoadLibrary. For some reason it crashes for 32-bit.
# Changing it to use dllimport makes it also work for 32-bit.
import sys
import traceback
import os.path
import collections
import ctypes
import cffi
import func
# Try to load the library from the selected directory
try:
import global_vars
directory = global_vars.avisynth_library_dir
except:
directory = ur''
if os.name == 'nt':
if directory:
ffi = cffi.FFI()
ffi.cdef('bool SetDllDirectoryW(wchar_t *);')
kernel32 = ffi.dlopen('kernel32')
if hasattr(kernel32, 'SetDllDirectoryW'):
kernel32.SetDllDirectoryW(directory)
if __debug__:
print('Using a custom AviSynth directory:', directory)
elif __debug__:
print ('No SetDllDirectoryW on this version of Windows, '
'using AviSynth from PATH')
elif __debug__:
print('Using AviSynth from PATH')
else: # TODO
if __debug__:
if directory:
print('Using a custom AvxSynth directory:', directory)
else:
print('Using AvxSynth from LD_LIBRARY_PATH')
propCharDict = {
'_Matrix': func.GetMatrixName,
'_Primaries': func.GetColorPrimariesName,
'_ChromaLocation': func.GetChromaLocationName,
'_FieldBased': func.GetFieldBasedName,
'_Transfer': func.GetTransferName,
'_ColorRange': func.GetColorRangeName,
'_GOPClosed': func.GetGOPClosedName,
}
sys_encoding = sys.getfilesystemencoding()
encoding = sys_encoding
abi = False
cdef_str = r"""
typedef unsigned char BYTE;
typedef int64_t INT64;
typedef void *PVOID;
typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;
typedef HINSTANCE HMODULE;
enum { AVISYNTH_INTERFACE_VERSION = ... };
enum {AVS_SAMPLE_INT8 = ..., // 1<<0,
AVS_SAMPLE_INT16 = ..., // 1<<1,
AVS_SAMPLE_INT24 = ..., // 1<<2,
AVS_SAMPLE_INT32 = ..., // 1<<3,
AVS_SAMPLE_FLOAT = ... // 1<<4
};
enum {AVS_PLANAR_Y = ..., // 1<<0,
AVS_PLANAR_U = ..., // 1<<1,
AVS_PLANAR_V = ..., // 1<<2,
AVS_PLANAR_ALIGNED = ..., // 1<<3,
AVS_PLANAR_Y_ALIGNED = ..., // AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
AVS_PLANAR_U_ALIGNED = ..., // AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
AVS_PLANAR_V_ALIGNED = ..., // AVS_PLANAR_V|AVS_PLANAR_ALIGNED,
AVS_PLANAR_A = ..., // 1<<4,
AVS_PLANAR_R = ..., // 1<<5,
AVS_PLANAR_G = ..., // 1<<6,
AVS_PLANAR_B = ..., // 1<<7,
AVS_PLANAR_A_ALIGNED = ..., // AVS_PLANAR_A|AVS_PLANAR_ALIGNED,
AVS_PLANAR_R_ALIGNED = ..., // AVS_PLANAR_R|AVS_PLANAR_ALIGNED,
AVS_PLANAR_G_ALIGNED = ..., // AVS_PLANAR_G|AVS_PLANAR_ALIGNED,
AVS_PLANAR_B_ALIGNED = ... // AVS_PLANAR_B|AVS_PLANAR_ALIGNED
};
// Colorspace properties.
enum {
AVS_CS_YUVA = ..., // 1 << 27,
AVS_CS_BGR = ..., // 1 << 28,
AVS_CS_YUV = ..., // 1 << 29,
AVS_CS_INTERLEAVED = ..., // = 1 << 30,
AVS_CS_PLANAR = ..., // = 1 << 31,
AVS_CS_SHIFT_SUB_WIDTH = ..., // = 0,
AVS_CS_SHIFT_SUB_HEIGHT = ..., // = 8,
AVS_CS_SHIFT_SAMPLE_BITS = ..., // = 16,
AVS_CS_SUB_WIDTH_MASK = ..., // 7 << AVS_CS_SHIFT_SUB_WIDTH,
AVS_CS_SUB_WIDTH_1 = ..., // 3 << AVS_CS_SHIFT_SUB_WIDTH, // YV24
AVS_CS_SUB_WIDTH_2 = ..., // 0 << AVS_CS_SHIFT_SUB_WIDTH, // YV12, I420, YV16
AVS_CS_SUB_WIDTH_4 = ..., // 1 << AVS_CS_SHIFT_SUB_WIDTH, // YUV9, YV411
AVS_CS_VPLANEFIRST = ..., // 1 << 3, // YV12, YV16, YV24, YV411, YUV9
AVS_CS_UPLANEFIRST = ..., // 1 << 4, // I420
AVS_CS_SUB_HEIGHT_MASK = ..., // 7 << AVS_CS_SHIFT_SUB_HEIGHT,
AVS_CS_SUB_HEIGHT_1 = ..., // 3 << AVS_CS_SHIFT_SUB_HEIGHT, // YV16, YV24, YV411
AVS_CS_SUB_HEIGHT_2 = ..., // 0 << AVS_CS_SHIFT_SUB_HEIGHT, // YV12, I420
AVS_CS_SUB_HEIGHT_4 = ..., // 1 << AVS_CS_SHIFT_SUB_HEIGHT, // YUV9
AVS_CS_SAMPLE_BITS_MASK = ..., // 7 << AVS_CS_SHIFT_SAMPLE_BITS,
AVS_CS_SAMPLE_BITS_8 = ..., // 0 << AVS_CS_SHIFT_SAMPLE_BITS,
AVS_CS_SAMPLE_BITS_10 = ..., // 5 << AVS_CS_SHIFT_SAMPLE_BITS,
AVS_CS_SAMPLE_BITS_12 = ..., // 6 << AVS_CS_SHIFT_SAMPLE_BITS,
AVS_CS_SAMPLE_BITS_14 = ..., // 7 << AVS_CS_SHIFT_SAMPLE_BITS,
AVS_CS_SAMPLE_BITS_16 = ..., // 1 << AVS_CS_SHIFT_SAMPLE_BITS,
AVS_CS_SAMPLE_BITS_32 = ..., // 2 << AVS_CS_SHIFT_SAMPLE_BITS,
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,
AVS_CS_PLANAR_FILTER = ..., // ~(AVS_CS_VPLANEFIRST | AVS_CS_UPLANEFIRST),
AVS_CS_RGB_TYPE = ..., // 1 << 0,
AVS_CS_RGBA_TYPE = ..., // 1 << 1,
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
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
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
AVS_CS_GENERIC_Y = ..., // AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV, // Y only (4:0:0)
AVS_CS_GENERIC_RGBP = ..., // AVS_CS_PLANAR | AVS_CS_BGR | AVS_CS_RGB_TYPE, // planar RGB
AVS_CS_GENERIC_RGBAP = ..., // AVS_CS_PLANAR | AVS_CS_BGR | AVS_CS_RGBA_TYPE, // planar RGBA
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
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
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
};
// Specific colorformats
enum {
AVS_CS_UNKNOWN = 0,
AVS_CS_BGR24 = ..., // AVS_CS_RGB_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED,
AVS_CS_BGR32 = ..., // AVS_CS_RGBA_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED,
AVS_CS_YUY2 = ..., // 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
// AVS_CS_YV12 = 1<<3 Reserved
// AVS_CS_I420 = 1<<4 Reserved
AVS_CS_RAW32 = ..., // 1<<5 | AVS_CS_INTERLEAVED,
AVS_CS_YV24 = ..., // AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_8, // YVU 4:4:4 planar
AVS_CS_YV16 = ..., // AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_8, // YVU 4:2:2 planar
AVS_CS_YV12 = ..., // AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_8, // YVU 4:2:0 planar
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
AVS_CS_IYUV = ..., // AVS_CS_I420,
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
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
AVS_CS_Y8 = ..., // AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_8, // Y 4:0:0 planar
//-------------------------
// AVS16: new planar constants go live! Experimental PF 160613
// 10-12-14-16 bit + planar RGB + BRG48/64 160725
AVS_CS_YUV444P10 = ..., // AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_10, // YUV 4:4:4 10bit samples
AVS_CS_YUV422P10 = ..., // AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_10, // YUV 4:2:2 10bit samples
AVS_CS_YUV420P10 = ..., // AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_10, // YUV 4:2:0 10bit samples
AVS_CS_Y10 = ..., // AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_10, // Y 4:0:0 10bit samples
AVS_CS_YUV444P12 = ..., // AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_12, // YUV 4:4:4 12bit samples
AVS_CS_YUV422P12 = ..., // AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_12, // YUV 4:2:2 12bit samples
AVS_CS_YUV420P12 = ..., // AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_12, // YUV 4:2:0 12bit samples
AVS_CS_Y12 = ..., // AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_12, // Y 4:0:0 12bit samples
AVS_CS_YUV444P14 = ..., // AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_14, // YUV 4:4:4 14bit samples
AVS_CS_YUV422P14 = ..., // AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_14, // YUV 4:2:2 14bit samples
AVS_CS_YUV420P14 = ..., // AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_14, // YUV 4:2:0 14bit samples
AVS_CS_Y14 = ..., // AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_14, // Y 4:0:0 14bit samples
AVS_CS_YUV444P16 = ..., // AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_16, // YUV 4:4:4 16bit samples
AVS_CS_YUV422P16 = ..., // AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_16, // YUV 4:2:2 16bit samples
AVS_CS_YUV420P16 = ..., // AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_16, // YUV 4:2:0 16bit samples
AVS_CS_Y16 = ..., // AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_16, // Y 4:0:0 16bit samples
// 32 bit samples (float)
AVS_CS_YUV444PS = ..., // AVS_CS_GENERIC_YUV444 | AVS_CS_SAMPLE_BITS_32, // YUV 4:4:4 32bit samples
AVS_CS_YUV422PS = ..., // AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_32, // YUV 4:2:2 32bit samples
AVS_CS_YUV420PS = ..., // AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_32, // YUV 4:2:0 32bit samples
AVS_CS_Y32 = ..., // AVS_CS_GENERIC_Y | AVS_CS_SAMPLE_BITS_32, // Y 4:0:0 32bit samples
// RGB packed
AVS_CS_BGR48 = ..., // AVS_CS_RGB_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED | AVS_CS_SAMPLE_BITS_16, // BGR 3x16 bit
AVS_CS_BGR64 = ..., // AVS_CS_RGBA_TYPE | AVS_CS_BGR | AVS_CS_INTERLEAVED | AVS_CS_SAMPLE_BITS_16, // BGR 4x16 bit
// no packed 32 bit (float) support for these legacy types
// RGB planar
AVS_CS_RGBP = ..., // AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_8, // Planar RGB 8 bit samples
AVS_CS_RGBP10 = ..., // AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_10, // Planar RGB 10bit samples
AVS_CS_RGBP12 = ..., // AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_12, // Planar RGB 12bit samples
AVS_CS_RGBP14 = ..., // AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_14, // Planar RGB 14bit samples
AVS_CS_RGBP16 = ..., // AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_16, // Planar RGB 16bit samples
AVS_CS_RGBPS = ..., // AVS_CS_GENERIC_RGBP | AVS_CS_SAMPLE_BITS_32, // Planar RGB 32bit samples
// RGBA planar
AVS_CS_RGBAP = ..., // AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_8, // Planar RGBA 8 bit samples
AVS_CS_RGBAP10 = ..., // AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_10, // Planar RGBA 10bit samples
AVS_CS_RGBAP12 = ..., // AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_12, // Planar RGBA 12bit samples
AVS_CS_RGBAP14 = ..., // AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_14, // Planar RGBA 14bit samples
AVS_CS_RGBAP16 = ..., // AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_16, // Planar RGBA 16bit samples
AVS_CS_RGBAPS = ..., // AVS_CS_GENERIC_RGBAP | AVS_CS_SAMPLE_BITS_32, // Planar RGBA 32bit samples
// Planar YUVA
AVS_CS_YUVA444 = ..., // AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_8, // YUVA 4:4:4 8bit samples
AVS_CS_YUVA422 = ..., // AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_8, // YUVA 4:2:2 8bit samples
AVS_CS_YUVA420 = ..., // AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_8, // YUVA 4:2:0 8bit samples
AVS_CS_YUVA444P10 = ..., // AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:4:4 10bit samples
AVS_CS_YUVA422P10 = ..., // AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:2:2 10bit samples
AVS_CS_YUVA420P10 = ..., // AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_10, // YUVA 4:2:0 10bit samples
AVS_CS_YUVA444P12 = ..., // AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:4:4 12bit samples
AVS_CS_YUVA422P12 = ..., // AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:2:2 12bit samples
AVS_CS_YUVA420P12 = ..., // AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_12, // YUVA 4:2:0 12bit samples
AVS_CS_YUVA444P14 = ..., // AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:4:4 14bit samples
AVS_CS_YUVA422P14 = ..., // AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:2:2 14bit samples
AVS_CS_YUVA420P14 = ..., // AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_14, // YUVA 4:2:0 14bit samples
AVS_CS_YUVA444P16 = ..., // AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:4:4 16bit samples
AVS_CS_YUVA422P16 = ..., // AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:2:2 16bit samples
AVS_CS_YUVA420P16 = ..., // AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_16, // YUVA 4:2:0 16bit samples
AVS_CS_YUVA444PS = ..., // AVS_CS_GENERIC_YUVA444 | AVS_CS_SAMPLE_BITS_32, // YUVA 4:4:4 32bit samples
AVS_CS_YUVA422PS = ..., // AVS_CS_GENERIC_YUVA422 | AVS_CS_SAMPLE_BITS_32, // YUVA 4:2:2 32bit samples
AVS_CS_YUVA420PS = ... // AVS_CS_GENERIC_YUVA420 | AVS_CS_SAMPLE_BITS_32, // YUVA 4:2:0 32bit samples
};
enum {
AVS_IT_BFF = ..., // 1<<0,
AVS_IT_TFF = ..., // 1<<1,
AVS_IT_FIELDBASED = ... // 1<<2
};
enum {
AVS_FILTER_TYPE=1,
AVS_FILTER_INPUT_COLORSPACE=2,
AVS_FILTER_OUTPUT_TYPE=9,
AVS_FILTER_NAME=4,
AVS_FILTER_AUTHOR=5,
AVS_FILTER_VERSION=6,
AVS_FILTER_ARGS=7,
AVS_FILTER_ARGS_INFO=8,
AVS_FILTER_ARGS_DESCRIPTION=10,
AVS_FILTER_DESCRIPTION=11};
enum { //SUBTYPES
AVS_FILTER_TYPE_AUDIO=1,
AVS_FILTER_TYPE_VIDEO=2,
AVS_FILTER_OUTPUT_TYPE_SAME=3,
AVS_FILTER_OUTPUT_TYPE_DIFFERENT=4};
enum {
// New 2.6 explicitly defined cache hints.
AVS_CACHE_NOTHING=10, // Do not cache video.
AVS_CACHE_WINDOW=11, // Hard protect upto X frames within a range of X from the current frame N.
AVS_CACHE_GENERIC=12, // LRU cache upto X frames.
AVS_CACHE_FORCE_GENERIC=13, // LRU cache upto X frames, override any previous CACHE_WINDOW.
AVS_CACHE_GET_POLICY=30, // Get the current policy.
AVS_CACHE_GET_WINDOW=31, // Get the current window h_span.
AVS_CACHE_GET_RANGE=32, // Get the current generic frame range.
AVS_CACHE_AUDIO=50, // Explicitly do cache audio, X byte cache.
AVS_CACHE_AUDIO_NOTHING=51, // Explicitly do not cache audio.
AVS_CACHE_AUDIO_NONE=52, // Audio cache off (auto mode), X byte intial cache.
AVS_CACHE_AUDIO_AUTO=53, // Audio cache on (auto mode), X byte intial cache.
AVS_CACHE_GET_AUDIO_POLICY=70, // Get the current audio policy.
AVS_CACHE_GET_AUDIO_SIZE=71, // Get the current audio cache size.
AVS_CACHE_PREFETCH_FRAME=100, // Queue request to prefetch frame N.
AVS_CACHE_PREFETCH_GO=101, // Action video prefetches.
AVS_CACHE_PREFETCH_AUDIO_BEGIN=120, // Begin queue request transaction to prefetch audio (take critical section).
AVS_CACHE_PREFETCH_AUDIO_STARTLO=121, // Set low 32 bits of start.
AVS_CACHE_PREFETCH_AUDIO_STARTHI=122, // Set high 32 bits of start.
AVS_CACHE_PREFETCH_AUDIO_COUNT=123, // Set low 32 bits of length.
AVS_CACHE_PREFETCH_AUDIO_COMMIT=124, // Enqueue request transaction to prefetch audio (release critical section).
AVS_CACHE_PREFETCH_AUDIO_GO=125, // Action audio prefetches.
AVS_CACHE_GETCHILD_CACHE_MODE=200, // Cache ask Child for desired video cache mode.
AVS_CACHE_GETCHILD_CACHE_SIZE=201, // Cache ask Child for desired video cache size.
AVS_CACHE_GETCHILD_AUDIO_MODE=202, // Cache ask Child for desired audio cache mode.
AVS_CACHE_GETCHILD_AUDIO_SIZE=203, // Cache ask Child for desired audio cache size.
AVS_CACHE_GETCHILD_COST=220, // Cache ask Child for estimated processing cost.
AVS_CACHE_COST_ZERO=221, // Child response of zero cost (ptr arithmetic only). AVS_CACHE_COST_UNIT=222, // Child response of unit cost (less than or equal 1 full frame blit).
AVS_CACHE_COST_LOW=223, // Child response of light cost. (Fast)
AVS_CACHE_COST_MED=224, // Child response of medium cost. (Real time)
AVS_CACHE_COST_HI=225, // Child response of heavy cost. (Slow)
AVS_CACHE_GETCHILD_THREAD_MODE=240, // Cache ask Child for thread safetyness.
AVS_CACHE_THREAD_UNSAFE=241, // Only 1 thread allowed for all instances. 2.5 filters default!
AVS_CACHE_THREAD_CLASS=242, // Only 1 thread allowed for each instance. 2.6 filters default!
AVS_CACHE_THREAD_SAFE=243, // Allow all threads in any instance.
AVS_CACHE_THREAD_OWN=244, // Safe but limit to 1 thread, internally threaded.
AVS_CACHE_GETCHILD_ACCESS_COST=260, // Cache ask Child for preferred access pattern.
AVS_CACHE_ACCESS_RAND=261, // Filter is access order agnostic.
AVS_CACHE_ACCESS_SEQ0=262, // Filter prefers sequential access (low cost)
AVS_CACHE_ACCESS_SEQ1=263, // Filter needs sequential access (high cost)
AVS_CACHE_AVSPLUS_CONSTANTS = 500, // Smaller values are reserved for classic Avisynth
AVS_CACHE_DONT_CACHE_ME = 501, // Filters that don't need caching (eg. trim, cache etc.) should return 1 to this request
AVS_CACHE_SET_MIN_CAPACITY = 502,
AVS_CACHE_SET_MAX_CAPACITY = 503,
AVS_CACHE_GET_MIN_CAPACITY = 504,
AVS_CACHE_GET_MAX_CAPACITY = 505,
AVS_CACHE_GET_SIZE = 506,
AVS_CACHE_GET_REQUESTED_CAP = 507,
AVS_CACHE_GET_CAPACITY = 508,
AVS_CACHE_GET_MTMODE = 509,
AVS_CACHE_IS_CACHE_REQ = 510,
AVS_CACHE_IS_CACHE_ANS = 511,
AVS_CACHE_IS_MTGUARD_REQ = 512,
AVS_CACHE_IS_MTGUARD_ANS = 513,
AVS_CACHE_AVSPLUS_CUDA_CONSTANTS = 600,
AVS_CACHE_GET_DEV_TYPE = 601, // Device types a filter can return
AVS_CACHE_GET_CHILD_DEV_TYPE = 602, // Device types a fitler can receive
AVS_CACHE_USER_CONSTANTS = 1000 // Smaller values are reserved for the core
};
// enums for frame property functions
// AVSPropTypes
enum {
AVS_PROPTYPE_UNSET = 'u',
AVS_PROPTYPE_INT = 'i',
AVS_PROPTYPE_FLOAT = 'f',
AVS_PROPTYPE_DATA = 's',
AVS_PROPTYPE_CLIP = 'c',
AVS_PROPTYPE_FRAME = 'v'
};
// AVSGetPropErrors for avs_prop_get_...
enum {
AVS_GETPROPERROR_UNSET = 1,
AVS_GETPROPERROR_TYPE = 2,
AVS_GETPROPERROR_INDEX = 4
};
// AVSPropAppendMode for avs_prop_set_...
enum {
AVS_PROPAPPENDMODE_REPLACE = 0,
AVS_PROPAPPENDMODE_APPEND = 1,
AVS_PROPAPPENDMODE_TOUCH = 2
};
// AvsEnvProperty for avs_get_env_property
enum
{
AVS_AEP_PHYSICAL_CPUS = 1,
AVS_AEP_LOGICAL_CPUS = 2,
AVS_AEP_THREADPOOL_THREADS = 3,
AVS_AEP_FILTERCHAIN_THREADS = 4,
AVS_AEP_THREAD_ID = 5,
AVS_AEP_VERSION = 6,
// Neo additionals
AVS_AEP_NUM_DEVICES = 901,
AVS_AEP_FRAME_ALIGN = 902,
AVS_AEP_PLANE_ALIGN = 903,
AVS_AEP_SUPPRESS_THREAD = 921,
AVS_AEP_GETFRAME_RECURSIVE = 922
};
// enum AvsAllocType for avs_allocate
enum {
AVS_ALLOCTYPE_NORMAL_ALLOC = 1,
AVS_ALLOCTYPE_POOLED_ALLOC = 2
};
#define AVS_FRAME_ALIGN ...
typedef struct AVS_Clip AVS_Clip;
typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
/////////////////////////////////////////////////////////////////////
//
// AVS_VideoInfo
//
// AVS_VideoInfo is layed out identicly to VideoInfo
typedef struct AVS_VideoInfo {
int width, height; // width=0 means no video
unsigned fps_numerator, fps_denominator;
int num_frames;
int pixel_type;
int audio_samples_per_second; // 0 means no audio
int sample_type;
INT64 num_audio_samples;
int nchannels;
// Imagetype properties
int image_type;
} AVS_VideoInfo;
// useful functions of the above - functions with AVSC_INLINE
int avs_has_video(const AVS_VideoInfo * p);
int avs_has_audio(const AVS_VideoInfo * p);
int avs_is_rgb(const AVS_VideoInfo * p);
int avs_is_rgb24(const AVS_VideoInfo * p);
int avs_is_rgb32(const AVS_VideoInfo * p);
int avs_is_yuv(const AVS_VideoInfo * p);
int avs_is_yuy2(const AVS_VideoInfo * p);
// became a real interface function int avs_is_yv24(const AVS_VideoInfo * p);
// became a real interface function int avs_is_yv16(const AVS_VideoInfo * p);
// became a real interface function int avs_is_yv12(const AVS_VideoInfo * p);
// became a real interface function int avs_is_yv411(const AVS_VideoInfo * p);
// became a real interface function int avs_is_y8(const AVS_VideoInfo * p);
int avs_is_property(const AVS_VideoInfo * p, int property);
int avs_is_planar(const AVS_VideoInfo * p);
// became a real interface function int avs_is_color_space(const AVS_VideoInfo * p, int c_space);
int avs_is_field_based(const AVS_VideoInfo * p);
int avs_is_parity_known(const AVS_VideoInfo * p);
int avs_is_bff(const AVS_VideoInfo * p);
int avs_is_tff(const AVS_VideoInfo * p);
// became a real interface function int avs_bits_per_pixel(const AVS_VideoInfo * p);
// became a real interface function int avs_bytes_from_pixels(const AVS_VideoInfo * p, int pixels); // Will work on planar images, but will return only luma planes
// became a real interface function int avs_row_size(const AVS_VideoInfo * p); // Also only returns first plane on planar images Fixed in V6: plane parameter
// became a real interface function int avs_bmp_size(const AVS_VideoInfo * vi);
int avs_samples_per_second(const AVS_VideoInfo * p);
int avs_bytes_per_channel_sample(const AVS_VideoInfo * p);
int avs_bytes_per_audio_sample(const AVS_VideoInfo * p);
INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames);
int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples);
INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes);
INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples);
int avs_audio_channels(const AVS_VideoInfo * p);
int avs_sample_type(const AVS_VideoInfo * p);
void avs_set_property(AVS_VideoInfo * p, int property); // useful mutator
void avs_clear_property(AVS_VideoInfo * p, int property);
void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased);
void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator);
// special: this inline function calls an API function
// Nevertheless it's not much use here, don't implement is
// int avs_is_same_colorspace(const AVS_VideoInfo * x, const AVS_VideoInfo * y);
/////////////////////////////////////////////////////////////////////
//
// AVS_VideoFrame
//
// VideoFrameBuffer holds information about a memory block which is used
// for video data. For efficiency, instances of this class are not deleted
// when the refcount reaches zero; instead they're stored in a linked list
// to be reused. The instances are deleted when the corresponding AVS
// file is closed.
// AVS_VideoFrameBuffer is layed out identicly to VideoFrameBuffer
// DO NOT USE THIS STRUCTURE DIRECTLY
typedef struct AVS_VideoFrameBuffer {
BYTE * data;
int data_size;
// sequence_number is incremented every time the buffer is changed, so
// that stale views can tell they're no longer valid.
volatile long sequence_number;
volatile long refcount;
void * device; // avs+
} AVS_VideoFrameBuffer;
// VideoFrame holds a "window" into a VideoFrameBuffer.
// AVS_VideoFrame is layed out identicly to IVideoFrame
// DO NOT USE THIS STRUCTURE DIRECTLY
typedef struct AVS_VideoFrame {
volatile long refcount;
AVS_VideoFrameBuffer * vfb;
int offset;
int pitch, row_size, height;
int offsetU, offsetV;
int pitchUV; // U&V offsets are from top of picture.
int row_sizeUV, heightUV; // for Planar RGB offsetU, offsetV is for the 2nd and 3rd Plane.
// for Planar RGB pitchUV and row_sizeUV = 0, because when no VideoInfo (MakeWriteable)
// the decision on existance of UV is checked by zero pitch
// AVS+ extension, avisynth.h: class does not break plugins if appended here
int offsetA;
int pitchA, row_sizeA; // 4th alpha plane support, pitch and row_size is 0 is none
void * properties;
} AVS_VideoFrame;
// Access functions for AVS_VideoFrame
// Special: this AVSC_INLINE is calling a real interface function
// int avs_get_pitch(const AVS_VideoFrame * p);
// became a real interface function
// int avs_get_pitch_p(const AVS_VideoFrame * p, int plane);
// Special: this AVSC_INLINE is calling a real interface function
// int avs_get_row_size(const AVS_VideoFrame * p);
// became a real interface function
// int avs_get_row_size_p(const AVS_VideoFrame * p, int plane);
// Special: this AVSC_INLINE is calling a real interface function
// int avs_get_height(const AVS_VideoFrame * p);
// became a real interface function
// int avs_get_height_p(const AVS_VideoFrame * p, int plane);
// Special: this AVSC_INLINE is calling a real interface function
// const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p);
// became a real interface function const BYTE* avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane);
// int avs_is_writable(const AVS_VideoFrame * p);
// Special: this AVSC_INLINE is calling a real interface function
// BYTE* avs_get_write_ptr(const AVS_VideoFrame * p);
// became a real interface function
// BYTE* avs_get_write_ptr_p(const AVS_VideoFrame * p, int plane);
typedef void (*avs_release_video_frame_func)(AVS_VideoFrame *);
// makes a shallow copy of a video frame
typedef AVS_VideoFrame * (*avs_copy_video_frame_func)(AVS_VideoFrame *);
// typedef int (*avs_row_size_func)(const AVS_VideoInfo * p, int plane);
// Properties
typedef struct AVS_Map {
void* data;
} AVS_Map;
// Properties new V8 Interface
typedef const AVS_Map* (*avs_get_frame_props_ro_func)(AVS_ScriptEnvironment* p, const AVS_VideoFrame* frame);
typedef int (*avs_prop_num_keys_func)(AVS_ScriptEnvironment* p, const AVS_Map* map);
typedef int (*avs_prop_num_elements_func)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key);
typedef const char* (*avs_prop_get_key_func)(AVS_ScriptEnvironment* p, const AVS_Map* map, int index);
typedef char (*avs_prop_get_type_func)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key);
typedef int64_t (*avs_prop_get_int_func)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int error);
typedef double (*avs_prop_get_float_func)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int error);
typedef const char* (*avs_prop_get_data_func)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int error);
typedef int (*avs_prop_get_data_size_func)(AVS_ScriptEnvironment* p, const AVS_Map* map, const char* key, int index, int error);
typedef void (*avs_clear_map_func)(AVS_ScriptEnvironment* p, AVS_Map* map);
// ------------- currently done until this
/////////////////////////////////////////////////////////////////////
//
// AVS_Value
//
// Treat AVS_Value as a fat pointer. That is use avs_copy_value
// and avs_release_value appropiaty as you would if AVS_Value was
// a pointer.
// To maintain source code compatibility with future versions of the
// avisynth_c API don't use the AVS_Value directly. Use the helper
// functions below.
// AVS_Value is layed out identicly to AVSValue
typedef struct AVS_Value AVS_Value;
struct AVS_Value {
short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
// for some function e'rror
short array_size;
union {
void * clip; // do not use directly, use avs_take_clip
char boolean;
int integer;
float floating_pt;
const char * string;
const AVS_Value * array;
} d;
};
// AVS_Value should be initilized with avs_void.
// Should also set to avs_void after the value is released
// with avs_copy_value. Consider it the equalvent of setting
// a pointer to NULL
static const AVS_Value avs_void = {'v'};
static const AVS_Value * avs_void_p;
//typedef void (*avs_copy_value_func)(AVS_Value * dest, AVS_Value src);
void avs_copy_value_w(AVS_Value * dest, AVS_Value * src);
//typedef void (*avs_release_value_func)(AVS_Value);
void avs_release_value_w(AVS_Value *);
//int avs_defined(AVS_Value v);
int avs_defined_w(AVS_Value *v);
//int avs_is_clip(AVS_Value v);
int avs_is_clip_w(AVS_Value *v);
//int avs_is_bool(AVS_Value v);
int avs_is_bool_w(AVS_Value *v);
//int avs_is_int(AVS_Value v);
int avs_is_int_w(AVS_Value *v);
//int avs_is_float(AVS_Value v);
int avs_is_float_w(AVS_Value *v);
//int avs_is_string(AVS_Value v);
int avs_is_string_w(AVS_Value *v);
//int avs_is_array(AVS_Value v);
int avs_is_array_w(AVS_Value *v);
//int avs_is_error(AVS_Value v);
int avs_is_error_w(AVS_Value *v);
//typedef AVS_Clip * (*avs_take_clip_func)(AVS_Value, AVS_ScriptEnvironment *);
AVS_Clip * avs_take_clip_w(AVS_Value *, AVS_ScriptEnvironment *);
typedef void (*avs_set_to_clip_func)(AVS_Value *, AVS_Clip *);
//int avs_as_bool(AVS_Value v);
int avs_as_bool_w(AVS_Value *v);
//int avs_as_int(AVS_Value v);
int avs_as_int_w(AVS_Value *v);
//const char * avs_as_string(AVS_Value v);
const char * avs_as_string_w(AVS_Value *v);
//double avs_as_float(AVS_Value v);
double avs_as_float_w(AVS_Value *v);
//const char * avs_as_error(AVS_Value v);
const char * avs_as_error_w(AVS_Value *v);
//const AVS_Value * avs_as_array(AVS_Value v);
const AVS_Value * avs_as_array_w(AVS_Value *v);
//int avs_array_size(AVS_Value v);
int avs_array_size_w(AVS_Value *v);
//AVS_Value avs_array_elt(AVS_Value v, int index);
AVS_Value * avs_array_elt_w(AVS_Value *v, int index);
// only use these functions on an AVS_Value that does not already have
// an active value. Remember, treat AVS_Value as a fat pointer.
//AVS_Value avs_new_value_bool(int v0);
void avs_new_value_bool_w(int v0, AVS_Value * v);
//AVS_Value avs_new_value_int(int v0);
void avs_new_value_int_w(int v0, AVS_Value * v);
//AVS_Value avs_new_value_string(const char * v0);
void avs_new_value_string_w(const char * v0, AVS_Value * v);
//AVS_Value avs_new_value_float(float v0);
void avs_new_value_float_w(float v0, AVS_Value * v);
//AVS_Value avs_new_value_error(const char * v0);
void avs_new_value_error_w(const char * v0, AVS_Value * v);
//AVS_Value avs_new_value_clip(AVS_Clip * v0);
void avs_new_value_clip_w(AVS_Clip * v0, AVS_Value * v);
//AVS_Value avs_new_value_array(AVS_Value * v0, int size);
void avs_new_value_array_w(AVS_Value * v0, int size, AVS_Value * v);
/////////////////////////////////////////////////////////////////////
//
// AVS_Clip
//
typedef void (*avs_release_clip_func)(AVS_Clip *);
typedef AVS_Clip * (*avs_copy_clip_func)(AVS_Clip *);
typedef const char * (*avs_clip_get_error_func)(AVS_Clip *); // return 0 if no error
typedef const AVS_VideoInfo * (*avs_get_video_info_func)(AVS_Clip *);
// new V6 Interface
typedef int (*avs_is_yv24_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_yv16_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_yv12_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_yv411_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_y8_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_color_space_func)(const AVS_VideoInfo * p, int c_space);
typedef int (*avs_get_plane_width_subsampling_func)(const AVS_VideoInfo * p, int plane);
typedef int (*avs_get_plane_height_subsampling_func)(const AVS_VideoInfo * p, int plane);
typedef int (*avs_bits_per_pixel_func)(const AVS_VideoInfo * p);
typedef int (*avs_bytes_from_pixels_func)(const AVS_VideoInfo * p, int pixels); // Will work on planar images, but will return only luma planes
typedef int (*avs_row_size_func)(const AVS_VideoInfo * p, int plane); // Also only returns first plane on planar images. Fixed in V6: plane parameter
typedef int (*avs_bmp_size_func)(const AVS_VideoInfo * vi);
// Access functions for AVS_VideoFrame
typedef int (*avs_get_pitch_p_func)(const AVS_VideoFrame * p, int plane);
typedef int (*avs_get_row_size_p_func)(const AVS_VideoFrame * p, int plane);
typedef int (*avs_get_height_p_func)(const AVS_VideoFrame * p, int plane);
typedef const BYTE * (*avs_get_read_ptr_p_func)(const AVS_VideoFrame * p, int plane);
typedef int (*avs_is_writable_func)(const AVS_VideoFrame * p);
typedef BYTE * (*avs_get_write_ptr_p_func)(const AVS_VideoFrame * p, int plane);
// Avisynth+ extensions
typedef int (*avs_is_rgb48_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_rgb64_func)(const AVS_VideoInfo * p);
// AVSC_API(int, avs_is_yuv444p16)(const AVS_VideoInfo * p); // obsolate, use avs_is_yuv444
// AVSC_API(int, avs_is_yuv422p16)(const AVS_VideoInfo * p); // obsolate, use avs_is_yuv422
// AVSC_API(int, avs_is_yuv420p16)(const AVS_VideoInfo * p); // obsolate, use avs_is_yuv420
// AVSC_API(int, avs_is_y16)(const AVS_VideoInfo * p); // obsolate, use avs_is_y
// AVSC_API(int, avs_is_yuv444ps)(const AVS_VideoInfo * p); // obsolate, use avs_is_yuv444
// AVSC_API(int, avs_is_yuv422ps)(const AVS_VideoInfo * p); // obsolate, use avs_is_yuv422
// AVSC_API(int, avs_is_yuv420ps)(const AVS_VideoInfo * p); // obsolate, use avs_is_yuv420
// AVSC_API(int, avs_is_y32)(const AVS_VideoInfo * p); // obsolate, use avs_is_y
typedef int (*avs_is_444_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_422_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_420_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_y_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_yuva_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_planar_rgb_func)(const AVS_VideoInfo * p);
typedef int (*avs_is_planar_rgba_func)(const AVS_VideoInfo * p);
typedef int (*avs_num_components_func)(const AVS_VideoInfo * p);
typedef int (*avs_component_size_func)(const AVS_VideoInfo * p);
typedef int (*avs_bits_per_component_func)(const AVS_VideoInfo * p);
// end of Avisynth+ specific
typedef int (*avs_get_version_func)(AVS_Clip *);
typedef AVS_VideoFrame * (*avs_get_frame_func)(AVS_Clip *, int n);
// The returned video frame must be released with avs_release_video_frame
typedef int (*avs_get_parity_func)(AVS_Clip *, int n);
// return field parity if field_based, else parity of first field in frame
typedef int (*avs_get_audio_func)(AVS_Clip *, void * buf,
INT64 start, INT64 count);
// start and count are in samples
typedef int (*avs_set_cache_hints_func)(AVS_Clip *,
int cachehints, int frame_range);
// XXX: AVS_ApplyFunc left out
// XXX: AVS_FilterInfo left out
// Create a new filter
// fi is set to point to the AVS_FilterInfo so that you can
// modify it once it is initilized.
// store_child should generally be set to true. If it is not
// set than ALL methods (the function pointers) must be defined
// If it is set than you do not need to worry about freeing the child
// clip.
typedef AVS_Clip * (*avs_new_c_filter_func)(AVS_ScriptEnvironment * e,
void * * fi,
void * child, int store_child);
/////////////////////////////////////////////////////////////////////
//
// AVS_ScriptEnvironment
//
enum {
/* slowest CPU to support extension */
AVS_CPU_FORCE = 0x01, // N/A
AVS_CPU_FPU = 0x02, // 386/486DX
AVS_CPU_MMX = 0x04, // P55C, K6, PII
AVS_CPU_INTEGER_SSE = 0x08, // PIII, Athlon
AVS_CPU_SSE = 0x10, // PIII, Athlon XP/MP
AVS_CPU_SSE2 = 0x20, // PIV, Hammer
AVS_CPU_3DNOW = 0x40, // K6-2
AVS_CPU_3DNOW_EXT = 0x80, // Athlon
AVS_CPU_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2,
// which only Hammer will have anyway)
AVS_CPUF_SSE3 = 0x100, // PIV+, K8 Venice
AVS_CPUF_SSSE3 = 0x200, // Core 2
AVS_CPUF_SSE4 = 0x400, // Penryn, Wolfdale, Yorkfield
AVS_CPUF_SSE4_1 = 0x400,
AVS_CPUF_AVX = 0x800, // Sandy Bridge, Bulldozer
AVS_CPUF_SSE4_2 = 0x1000, // Nehalem
// AVS+
AVS_CPUF_AVX2 = 0x2000, // Haswell
AVS_CPUF_FMA3 = 0x4000,
AVS_CPUF_F16C = 0x8000,
AVS_CPUF_MOVBE = 0x10000, // Big Endian Move
AVS_CPUF_POPCNT = 0x20000,
AVS_CPUF_AES = 0x40000,
AVS_CPUF_FMA4 = 0x80000,
AVS_CPUF_AVX512F = 0x100000, // AVX-512 Foundation.
AVS_CPUF_AVX512DQ = 0x200000, // AVX-512 DQ (Double/Quad granular) Instructions
AVS_CPUF_AVX512PF = 0x400000, // AVX-512 Prefetch
AVS_CPUF_AVX512ER = 0x800000, // AVX-512 Exponential and Reciprocal
AVS_CPUF_AVX512CD = 0x1000000, // AVX-512 Conflict Detection
AVS_CPUF_AVX512BW = 0x2000000, // AVX-512 BW (Byte/Word granular) Instructions
AVS_CPUF_AVX512VL = 0x4000000, // AVX-512 VL (128/256 Vector Length) Extensions
AVS_CPUF_AVX512IFMA = 0x8000000, // AVX-512 IFMA integer 52 bit
AVS_CPUF_AVX512VBMI = 0x10000000 // AVX-512 VBMI
};
typedef const char * (*avs_get_error_func)(AVS_ScriptEnvironment *); // return 0 if no error
typedef long (*avs_get_cpu_flags_func)(AVS_ScriptEnvironment *);
typedef int (*avs_check_version_func)(AVS_ScriptEnvironment *, int version);
typedef char * (*avs_save_string_func)(AVS_ScriptEnvironment *, const char* s, int length);
typedef char * (*avs_sprintf_func)(AVS_ScriptEnvironment *, const char * fmt, ...);
typedef char * (*avs_vsprintf_func)(AVS_ScriptEnvironment *, const char * fmt, void* val);
// note: val is really a va_list; I hope everyone typedefs va_list to a pointer
typedef int (*avs_add_function_func)(AVS_ScriptEnvironment *,
const char * name, const char * params,
void * apply, void * user_data);
typedef int (*avs_function_exists_func)(AVS_ScriptEnvironment *, const char * name);
//typedef AVS_Value (*avs_invoke_func)(AVS_ScriptEnvironment *, const char * name, AVS_Value args, const char** arg_names);
void avs_invoke_w(AVS_ScriptEnvironment *, const char * name, AVS_Value *args, const char** arg_names, AVS_Value *v);
// The returned value must be be released with avs_release_value
//typedef AVS_Value (*avs_get_var_func)(AVS_ScriptEnvironment *, const char* name);
void avs_get_var_w(AVS_ScriptEnvironment *env, const char* name, AVS_Value* v);
// The returned value must be be released with avs_release_value
//typedef int (*avs_set_var_func)(AVS_ScriptEnvironment *, const char* name, AVS_Value val);
int avs_set_var_w(AVS_ScriptEnvironment *, const char* name, AVS_Value* val);
//typedef int (*avs_set_global_var_func)(AVS_ScriptEnvironment *, const char* name, AVS_Value val);
int avs_set_global_var_w(AVS_ScriptEnvironment *, const char* name, const AVS_Value* val);
//void avs_push_context(AVS_ScriptEnvironment *, int level=0);
//void avs_pop_context(AVS_ScriptEnvironment *);
typedef AVS_VideoFrame * (*avs_new_video_frame_a_func)(AVS_ScriptEnvironment *,
const AVS_VideoInfo * vi, int align);
typedef int (*avs_make_writable_func)(AVS_ScriptEnvironment *, AVS_VideoFrame * * pvf);
typedef void (*avs_bit_blt_func)(AVS_ScriptEnvironment *, BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height);
typedef void (*AVS_ShutdownFunc)(void* user_data, AVS_ScriptEnvironment * env);
typedef void (*avs_at_exit_func)(AVS_ScriptEnvironment *, AVS_ShutdownFunc function, void * user_data);
typedef AVS_VideoFrame * (*avs_subframe_func)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height);
// The returned video frame must be be released
typedef int (*avs_set_memory_max_func)(AVS_ScriptEnvironment *, int mem);
typedef int (*avs_set_working_dir_func)(AVS_ScriptEnvironment *, const char * newdir);
// avisynth.dll exports this; it's a way to use it as a library, without
// writing an AVS script or without going through AVIFile.
typedef AVS_ScriptEnvironment * (*avs_create_script_environment_func)(int version);
typedef void (*avs_delete_script_environment_func)(AVS_ScriptEnvironment *);
typedef AVS_VideoFrame * (*avs_subframe_planar_func)(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);
// The returned video frame must be be released
void* malloc(size_t);
void free(void*);
HMODULE LoadLibrary(const char*);
void* GetProcAddress(HMODULE, const char*);
void FreeLibrary(HMODULE);
typedef struct AVS_Library{ ...; } AVS_Library;
// this section appears twice, see also in verify_str
avs_add_function_func avs_add_function;
avs_at_exit_func avs_at_exit;
avs_bit_blt_func avs_bit_blt;
avs_check_version_func avs_check_version;
avs_clip_get_error_func avs_clip_get_error;
// avs_copy_value_func avs_copy_value; // No! Has wrapper function
avs_copy_clip_func avs_copy_clip;
avs_copy_video_frame_func avs_copy_video_frame;
avs_create_script_environment_func avs_create_script_environment;
avs_delete_script_environment_func avs_delete_script_environment;
avs_function_exists_func avs_function_exists;
avs_get_audio_func avs_get_audio;
avs_get_cpu_flags_func avs_get_cpu_flags;
avs_get_frame_func avs_get_frame;
avs_get_parity_func avs_get_parity;
// avs_get_var_func avs_get_var; // // No! Has wrapper function
avs_get_version_func avs_get_version;
avs_get_video_info_func avs_get_video_info;
// avs_invoke_func avs_invoke; // No! Has wrapper function
avs_make_writable_func avs_make_writable;
avs_new_c_filter_func avs_new_c_filter;
avs_new_video_frame_a_func avs_new_video_frame_a;
avs_release_clip_func avs_release_clip;
// avs_release_value_func avs_release_value; // No! Has wrapper function
avs_release_video_frame_func avs_release_video_frame;
avs_save_string_func avs_save_string;
avs_set_cache_hints_func avs_set_cache_hints;
// avs_set_global_var_func avs_set_global_var; // No! Has wrapper function
avs_set_memory_max_func avs_set_memory_max;
avs_set_to_clip_func avs_set_to_clip; // NEW! todo check its usage
// avs_set_var_func avs_set_var; // No! Has wrapper function
avs_set_working_dir_func avs_set_working_dir;
avs_sprintf_func avs_sprintf;
avs_subframe_func avs_subframe;
avs_subframe_planar_func avs_subframe_planar;
// avs_take_clip_func avs_take_clip; // No! Has wrapper function
avs_vsprintf_func avs_vsprintf;
avs_get_error_func avs_get_error;
// new V6
avs_is_yv24_func avs_is_yv24;
avs_is_yv16_func avs_is_yv16;
avs_is_yv12_func avs_is_yv12;
avs_is_yv411_func avs_is_yv411;
avs_is_y8_func avs_is_y8;
avs_is_color_space_func avs_is_color_space;
avs_get_plane_width_subsampling_func avs_get_plane_width_subsampling;
avs_get_plane_height_subsampling_func avs_get_plane_height_subsampling;
avs_bits_per_pixel_func avs_bits_per_pixel;
avs_bytes_from_pixels_func avs_bytes_from_pixels;
avs_row_size_func avs_row_size;
avs_bmp_size_func avs_bmp_size;
avs_get_pitch_p_func avs_get_pitch_p;
avs_get_row_size_p_func avs_get_row_size_p;
avs_get_height_p_func avs_get_height_p;
avs_get_read_ptr_p_func avs_get_read_ptr_p;
avs_is_writable_func avs_is_writable;
avs_get_write_ptr_p_func avs_get_write_ptr_p;
// Avisynth+ specific
avs_is_rgb48_func avs_is_rgb48;
avs_is_rgb64_func avs_is_rgb64;
//some obsolate function
//AVSC_DECLARE_FUNC(avs_is_yuv444p16);
//AVSC_DECLARE_FUNC(avs_is_yuv422p16);
//AVSC_DECLARE_FUNC(avs_is_yuv420p16);
//AVSC_DECLARE_FUNC(avs_is_y16);
//AVSC_DECLARE_FUNC(avs_is_yuv444ps);
//AVSC_DECLARE_FUNC(avs_is_yuv422ps);
//AVSC_DECLARE_FUNC(avs_is_yuv420ps);
//AVSC_DECLARE_FUNC(avs_is_y32);
avs_is_444_func avs_is_444;
avs_is_422_func avs_is_422;
avs_is_420_func avs_is_420;
avs_is_y_func avs_is_y;
avs_is_yuva_func avs_is_yuva;
avs_is_planar_rgb_func avs_is_planar_rgb;
avs_is_planar_rgba_func avs_is_planar_rgba;
avs_num_components_func avs_num_components;
avs_component_size_func avs_component_size;
avs_bits_per_component_func avs_bits_per_component;
// _Properties avs+
avs_get_frame_props_ro_func avs_get_frame_props_ro;
avs_prop_num_keys_func avs_prop_num_keys;
avs_prop_get_key_func avs_prop_get_key;
avs_prop_num_elements_func avs_prop_num_elements;
avs_prop_get_type_func avs_prop_get_type;
avs_prop_get_int_func avs_prop_get_int;
avs_prop_get_float_func avs_prop_get_float;
avs_prop_get_data_func avs_prop_get_data;
avs_prop_get_data_size_func avs_prop_get_data_size;
avs_clear_map_func avs_clear_map;
// _End_Properties
// end of Avisynth+ specific
;AVS_Library * avs_load_library();
AVS_Library * avs_load_library_w();
void avs_free_library(AVS_Library *library);