-
Notifications
You must be signed in to change notification settings - Fork 4
/
avisynth_c.h
1769 lines (1466 loc) · 69.7 KB
/
avisynth_c.h
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 C Interface Version 0.20
// Copyright 2003 Kevin Atkinson
// Copyright 2020 AviSynth+ project
// 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., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301 USA, or visit
// http://www.gnu.org/copyleft/gpl.html .
//
// As a special exception, I give you permission to link to the
// Avisynth C interface with independent modules that communicate with
// the Avisynth C interface solely through the interfaces defined in
// avisynth_c.h, regardless of the license terms of these independent
// modules, and to copy and distribute the resulting combined work
// under terms of your choice, provided that every copy of the
// combined work is accompanied by a complete copy of the source code
// of the Avisynth C interface and Avisynth itself (with the version
// used to produce the combined work), being distributed under the
// terms of the GNU General Public License plus this exception. An
// independent module is a module which is not derived from or based
// on Avisynth C Interface, such as 3rd-party filters, import and
// export plugins, or graphical user interfaces.
// NOTE: this is a partial update of the Avisynth C interface to recognize
// new color spaces and interface elements added in Avisynth 2.60 and AviSynth+.
// This interface is not 100% Avisynth+ CPP interface equivalent.
// 170103: added new CPU constants (FMA4, AVX512xx)
// 171102: define SIZETMOD. do not use yet, experimental. Offsets are size_t instead of int. Affects x64.
// 171106: avs_get_row_size calls into avs_get_row_size_p, instead of direct field access
// 171106: avs_get_height calls into avs_get_row_size_p, instead of direct field access
// 180524: AVSC_EXPORT to dllexport in capi.h for avisynth_c_plugin_init
// 180524: avs_is_same_colorspace VideoInfo parameters to const
// 181230: Readability: functions regrouped to mix less AVSC_API and AVSC_INLINE, put together Avisynth+ specific stuff
// 181230: use #ifndef AVSC_NO_DECLSPEC for AVSC_INLINE functions which are calling API functions
// 181230: comments on avs_load_library (helper for loading API entries dynamically into a struct using AVSC_NO_DECLSPEC define)
// 181230: define alias AVS_FRAME_ALIGN as FRAME_ALIGN
// 181230: remove unused form of avs_get_rowsize and avs_get_height (kept earlier for reference)
// 190104: avs_load_library: smart fallback mechanism for Avisynth+ specific functions:
// if they are not loadable, they will work in a classic Avisynth compatible mode
// Example#1: e.g. avs_is_444 will call the existing avs_is_yv24 instead
// Example#2: avs_bits_per_component will return 8 for all colorspaces (Classic Avisynth supports only 8 bits/pixel)
// Thus the Avisynth+ specific API functions are safely callable even when connected to classic Avisynth DLL
// 202002xx non-Windows friendly additions
// 20200305 avs_vsprintf parameter type change: (void *) to va_list
// 20200330: (remove test SIZETMOD define for clarity)
// 20200513: user must use explicite #define AVS26_FALLBACK_SIMULATION for having fallback helpers in dynamic loaded library section
// 20200513: Follow AviSynth+ V8 interface additions
// AVS_VideoFrame struct extended with placeholder for frame property pointer
// avs_subframe_planar_a
// avs_copy_frame_props
// avs_get_frame_props_ro, avs_get_frame_props_rw
// avs_prop_num_keys, avs_prop_get_key, avs_prop_num_elements, avs_prop_get_type, avs_prop_get_data_size
// avs_prop_get_int, avs_prop_get_float, avs_prop_get_data, avs_prop_get_clip, avs_prop_get_frame, avs_prop_get_int_array, avs_prop_get_float_array
// avs_prop_set_int, avs_prop_set_float, avs_prop_set_data, avs_prop_set_clip, avs_prop_set_frame, avs_prop_set_int_array, avs_prop_set_float_array
// avs_prop_delete_key, avs_clear_map
// avs_new_video_frame_p, avs_new_video_frame_p_a
// avs_get_env_property (internal system properties), AVS_AEP_xxx (AvsEnvProperty) enums
// avs_get_var_try, avs_get_var_bool, avs_get_var_int, avs_get_var_double, avs_get_var_string, avs_get_var_long
// avs_pool_allocate, avs_pool_free
#ifndef __AVISYNTH_C__
#define __AVISYNTH_C__
#ifndef AVS_CONFIG_H
#define AVS_CONFIG_H
// Undefine this to get cdecl calling convention
#define AVSC_USE_STDCALL 1
// NOTE TO PLUGIN AUTHORS:
// Because AVS_FRAME_ALIGN can be substantially higher than the alignment
// a plugin actually needs, plugins should not use AVS_FRAME_ALIGN to check for
// alignment. They should always request the exact alignment value they need.
// This is to make sure that plugins work over the widest range of AviSynth
// builds possible.
#define AVS_FRAME_ALIGN 64
#if defined(_M_AMD64) || defined(__x86_64)
# define AVS_X86_64
#elif defined(_M_IX86) || defined(__i386__)
# define AVS_X86_32
// VS2017 introduced _M_ARM64
#elif defined(_M_ARM64) || defined(__aarch64__)
# define AVS_ARM64
#elif defined(_M_ARM) || defined(__arm__)
# define AVS_ARM32
#elif defined(__PPC64__)
# define AVS_PPC64
#elif defined(_M_PPC) || defined(__PPC__) || defined(__POWERPC__)
# define AVS_PPC32
#elif defined(__riscv)
# define AVS_RISCV
#elif defined(__sparc_v9__)
# define AVS_SPARC
#endif
// VC++ LLVM-Clang-cl MinGW-Gnu
// AVS_MSVC x x
// AVS_MSVC_PURE x
// AVS_CLANG x
// AVS_GCC x
#if defined(__clang__)
// Check clang first. clang-cl also defines __MSC_VER
// We set AVS_MSVC because they are mostly compatible
# define AVS_CLANG
#if defined(_MSC_VER)
# define AVS_MSVC
#endif
#elif defined(_MSC_VER)
# define AVS_MSVC
# define AVS_MSVC_PURE
#elif defined(__GNUC__)
# define AVS_GCC
#endif
#if defined(_WIN32) || defined(__CYGWIN__)
# define AVS_WINDOWS
#elif defined(__linux__)
# define AVS_LINUX
# define AVS_POSIX
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
# define AVS_BSD
# define AVS_POSIX
#elif defined(__APPLE__)
# define AVS_MACOS
# define AVS_POSIX
#elif defined(__HAIKU__)
# define AVS_HAIKU
# define AVS_POSIX
#endif
#ifndef AVS_MSVC
// GCC and Clang can be used on big endian systems, MSVC can't.
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define AVS_ENDIANNESS "little"
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define AVS_ENDIANNESS "big"
# else
# define AVS_ENDIANNESS "middle"
# endif
#else
#define AVS_ENDIANNESS "little"
#endif
#endif //AVS_CONFIG_H
#ifndef AVS_CAPI_H
#define AVS_CAPI_H
#ifdef AVS_POSIX
// this is also defined in avs/posix.h
#ifndef AVS_HAIKU
#define __declspec(x)
#endif
#endif
#ifdef __cplusplus
# define EXTERN_C extern "C"
#else
# define EXTERN_C
#endif
#ifdef AVS_WINDOWS
#ifdef BUILDING_AVSCORE
# if defined(AVS_GCC) && defined(AVS_X86_32)
# define AVSC_CC
# else // MSVC builds and 64-bit GCC
# ifndef AVSC_USE_STDCALL
# define AVSC_CC __cdecl
# else
# define AVSC_CC __stdcall
# endif
# endif
#else // needed for programs that talk to AviSynth+
# ifndef AVSC_WIN32_GCC32 // see comment below
# ifndef AVSC_USE_STDCALL
# define AVSC_CC __cdecl
# else
# define AVSC_CC __stdcall
# endif
# else
# define AVSC_CC
# endif
#endif
# else
# define AVSC_CC
#endif
// On 64-bit Windows, there's only one calling convention,
// so there is no difference between MSVC and GCC. On 32-bit,
// this isn't true. The convention that GCC needs to use to
// even build AviSynth+ as 32-bit makes anything that uses
// it incompatible with 32-bit MSVC builds of AviSynth+.
// The AVSC_WIN32_GCC32 define is meant to provide a user
// switchable way to make builds of FFmpeg to test 32-bit
// GCC builds of AviSynth+ without having to screw around
// with alternate headers, while still default to the usual
// situation of using 32-bit MSVC builds of AviSynth+.
// Hopefully, this situation will eventually be resolved
// and a broadly compatible solution will arise so the
// same 32-bit FFmpeg build can handle either MSVC or GCC
// builds of AviSynth+.
#define AVSC_INLINE static __inline
#ifdef BUILDING_AVSCORE
#ifdef AVS_WINDOWS
# ifndef AVS_STATIC_LIB
# define AVSC_EXPORT __declspec(dllexport)
# else
# define AVSC_EXPORT
# endif
# define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name
#else
# define AVSC_EXPORT EXTERN_C
# define AVSC_API(ret, name) EXTERN_C ret AVSC_CC name
#endif
#else
# define AVSC_EXPORT EXTERN_C __declspec(dllexport)
# ifndef AVS_STATIC_LIB
# define AVSC_IMPORT __declspec(dllimport)
# else
# define AVSC_IMPORT
# endif
# ifndef AVSC_NO_DECLSPEC
# define AVSC_API(ret, name) EXTERN_C AVSC_IMPORT ret AVSC_CC name
# else
# define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func)
# endif
#endif
#endif //AVS_CAPI_H
#ifndef AVS_TYPES_H
#define AVS_TYPES_H
// Define all types necessary for interfacing with avisynth.dll
#include <stdint.h>
// Raster types used by VirtualDub & Avisynth
typedef uint8_t BYTE;
#endif //AVS_TYPES_H
/////////////////////////////////////////////////////////////////////
//
// Constants
//
#ifndef __AVISYNTH_9_H__
enum {
AVISYNTH_INTERFACE_CLASSIC_VERSION = 6,
AVISYNTH_INTERFACE_VERSION = 9,
AVISYNTHPLUS_INTERFACE_BUGFIX_VERSION = 0 // reset to zero whenever the normal interface version bumps
};
#endif
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 color formats
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, // YUV 4:4:4 planar
AVS_CS_YV16 = AVS_CS_GENERIC_YUV422 | AVS_CS_SAMPLE_BITS_8, // YUV 4:2:2 planar
AVS_CS_YV12 = AVS_CS_GENERIC_YUV420 | AVS_CS_SAMPLE_BITS_8, // YUV 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, // YUV 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, // YUV 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 + BGR48/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 up to X frames within a range of X from the current frame N.
AVS_CACHE_GENERIC = 12, // LRU cache up to X frames.
AVS_CACHE_FORCE_GENERIC = 13, // LRU cache up to 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 initial cache.
AVS_CACHE_AUDIO_AUTO = 53, // Audio cache on (auto mode), X byte initial 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 safety.
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,
AVS_AEP_HOST_SYSTEM_ENDIANNESS = 7,
AVS_AEP_INTERFACE_VERSION = 8,
AVS_AEP_INTERFACE_BUGFIX = 9,
// 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
};
#ifdef BUILDING_AVSCORE
AVSValue create_c_video_filter(AVSValue args, void * user_data, IScriptEnvironment * e0);
struct AVS_ScriptEnvironment {
IScriptEnvironment * env;
const char * error;
AVS_ScriptEnvironment(IScriptEnvironment * e = 0)
: env(e), error(0) {}
};
#endif
typedef struct AVS_Clip AVS_Clip;
typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
/////////////////////////////////////////////////////////////////////
//
// AVS_VideoInfo
//
// AVS_VideoInfo is laid out identically 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_t num_audio_samples;
int nchannels;
// Image type properties
int image_type;
} AVS_VideoInfo;
// useful functions of the above
AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p)
{ return (p->width!=0); }
AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p)
{ return (p->audio_samples_per_second!=0); }
AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p)
{ return !!(p->pixel_type&AVS_CS_BGR); }
AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p)
{ return ((p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24) && ((p->pixel_type & AVS_CS_SAMPLE_BITS_MASK) == AVS_CS_SAMPLE_BITS_8); }
AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p)
{ return ((p->pixel_type&AVS_CS_BGR32)==AVS_CS_BGR32) && ((p->pixel_type & AVS_CS_SAMPLE_BITS_MASK) == AVS_CS_SAMPLE_BITS_8); }
AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p)
{ return !!(p->pixel_type&AVS_CS_YUV ); }
AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
{ return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
AVSC_API(int, avs_is_yv24)(const AVS_VideoInfo * p); // avs+: for generic 444 check, use avs_is_yuv444
AVSC_API(int, avs_is_yv16)(const AVS_VideoInfo * p); // avs+: for generic 422 check, use avs_is_yuv422
AVSC_API(int, avs_is_yv12)(const AVS_VideoInfo * p) ; // avs+: for generic 420 check, use avs_is_yuv420
AVSC_API(int, avs_is_yv411)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_y8)(const AVS_VideoInfo * p); // avs+: for generic grayscale, use avs_is_y
#ifdef AVSC_NO_DECLSPEC
AVSC_INLINE int avs_is_yv24(const AVS_VideoInfo * p)
{ return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV24 & AVS_CS_PLANAR_FILTER); }
AVSC_INLINE int avs_is_yv16(const AVS_VideoInfo * p)
{ return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV16 & AVS_CS_PLANAR_FILTER); }
AVSC_INLINE int avs_is_yv12(const AVS_VideoInfo * p)
{ return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV12 & AVS_CS_PLANAR_FILTER); }
AVSC_INLINE int avs_is_yv411(const AVS_VideoInfo * p)
{ return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_YV411 & AVS_CS_PLANAR_FILTER); }
AVSC_INLINE int avs_is_y8(const AVS_VideoInfo * p)
{ return (p->pixel_type & AVS_CS_PLANAR_MASK) == (AVS_CS_Y8 & AVS_CS_PLANAR_FILTER); }
#endif
AVSC_API(int, avs_get_plane_width_subsampling)(const AVS_VideoInfo * p, int plane);
AVSC_API(int, avs_get_plane_height_subsampling)(const AVS_VideoInfo * p, int plane);
AVSC_API(int, avs_bits_per_pixel)(const AVS_VideoInfo * p);
AVSC_API(int, avs_bytes_from_pixels)(const AVS_VideoInfo * p, int pixels);
AVSC_API(int, avs_row_size)(const AVS_VideoInfo * p, int plane);
AVSC_API(int, avs_bmp_size)(const AVS_VideoInfo * vi);
AVSC_API(int, avs_is_color_space)(const AVS_VideoInfo * p, int c_space);
// no API for these, inline helper functions
AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
{
return ((p->image_type & property) == property);
}
AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
{
return !!(p->pixel_type & AVS_CS_PLANAR);
}
AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
{
return !!(p->image_type & AVS_IT_FIELDBASED);
}
AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
{
return ((p->image_type & AVS_IT_FIELDBASED) && (p->image_type & (AVS_IT_BFF | AVS_IT_TFF)));
}
AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
{
return !!(p->image_type & AVS_IT_BFF);
}
AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
{
return !!(p->image_type & AVS_IT_TFF);
}
AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
{ return p->audio_samples_per_second; }
AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
{
switch (p->sample_type) {
case AVS_SAMPLE_INT8: return sizeof(signed char);
case AVS_SAMPLE_INT16: return sizeof(signed short);
case AVS_SAMPLE_INT24: return 3;
case AVS_SAMPLE_INT32: return sizeof(signed int);
case AVS_SAMPLE_FLOAT: return sizeof(float);
default: return 0;
}
}
AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
{ return p->nchannels*avs_bytes_per_channel_sample(p); }
AVSC_INLINE int64_t avs_audio_samples_from_frames(const AVS_VideoInfo * p, int64_t frames)
{ return ((int64_t)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, int64_t samples)
{ return (int)(samples * (int64_t)p->fps_numerator / (int64_t)p->fps_denominator / (int64_t)p->audio_samples_per_second); }
AVSC_INLINE int64_t avs_audio_samples_from_bytes(const AVS_VideoInfo * p, int64_t bytes)
{ return bytes / avs_bytes_per_audio_sample(p); }
AVSC_INLINE int64_t avs_bytes_from_audio_samples(const AVS_VideoInfo * p, int64_t samples)
{ return samples * avs_bytes_per_audio_sample(p); }
AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
{ return p->nchannels; }
AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
{ return p->sample_type; }
// useful mutator
// Note: these are video format properties, neither frame properties, nor system properties
AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
{ p->image_type|=property; }
AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)
{ p->image_type&=~property; }
AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)
{ if (isfieldbased) p->image_type|=AVS_IT_FIELDBASED; else p->image_type&=~AVS_IT_FIELDBASED; }
AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator)
{
unsigned x=numerator, y=denominator;
while (y) { // find gcd
unsigned t = x%y; x = y; y = t;
}
p->fps_numerator = numerator/x;
p->fps_denominator = denominator/x;
}
AVSC_INLINE int avs_is_same_colorspace(const AVS_VideoInfo * x, const AVS_VideoInfo * y)
{
return (x->pixel_type == y->pixel_type)
|| (avs_is_yv12(x) && avs_is_yv12(y));
}
// AviSynth+ extensions
AVSC_API(int, avs_is_rgb48)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_rgb64)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_yuv444p16)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv444
AVSC_API(int, avs_is_yuv422p16)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv422
AVSC_API(int, avs_is_yuv420p16)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv420
AVSC_API(int, avs_is_y16)(const AVS_VideoInfo * p); // deprecated, use avs_is_y
AVSC_API(int, avs_is_yuv444ps)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv444
AVSC_API(int, avs_is_yuv422ps)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv422
AVSC_API(int, avs_is_yuv420ps)(const AVS_VideoInfo * p); // deprecated, use avs_is_yuv420
AVSC_API(int, avs_is_y32)(const AVS_VideoInfo * p); // deprecated, use avs_is_y
AVSC_API(int, avs_is_444)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_422)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_420)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_y)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_yuva)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_planar_rgb)(const AVS_VideoInfo * p);
AVSC_API(int, avs_is_planar_rgba)(const AVS_VideoInfo * p);
AVSC_API(int, avs_num_components)(const AVS_VideoInfo * p);
AVSC_API(int, avs_component_size)(const AVS_VideoInfo * p);
AVSC_API(int, avs_bits_per_component)(const AVS_VideoInfo * p);
// end of Avisynth+ specific
/////////////////////////////////////////////////////////////////////
//
// 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 laid out identically 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 laid out identically 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 existence 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; // frame properties
} AVS_VideoFrame;
// Access functions for AVS_VideoFrame
AVSC_API(int, avs_get_pitch_p)(const AVS_VideoFrame * p, int plane);
AVSC_API(int, avs_get_row_size_p)(const AVS_VideoFrame * p, int plane);
AVSC_API(int, avs_get_height_p)(const AVS_VideoFrame * p, int plane);
AVSC_API(const BYTE *, avs_get_read_ptr_p)(const AVS_VideoFrame * p, int plane);
#ifdef AVSC_NO_DECLSPEC
AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame * p, int plane)
{
switch (plane) {
case AVS_PLANAR_U: case AVS_PLANAR_V:
return p->pitchUV;
case AVS_PLANAR_A:
return p->pitchA;
}
return p->pitch; // Y, G, B, R
}
AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame * p, int plane)
{
switch (plane) {
case AVS_PLANAR_U: case AVS_PLANAR_V:
return (p->pitchUV) ? p->row_sizeUV : 0;
case AVS_PLANAR_A:
return (p->pitchA) ? p->row_sizeA : 0;
}
return p->row_size;
}
AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame * p, int plane)
{
switch (plane) {
case AVS_PLANAR_U: case AVS_PLANAR_V:
return (p->pitchUV) ? p->heightUV : 0;
case AVS_PLANAR_A:
return (p->pitchA) ? p->height : 0;
}
return p->height; // Y, G, B, R, A
}
AVSC_INLINE const BYTE * avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane)
{
switch (plane) { // G is first. Then B,R order like U,V
case AVS_PLANAR_U: case AVS_PLANAR_B:
return p->vfb->data + p->offsetU;
case AVS_PLANAR_V: case AVS_PLANAR_R:
return p->vfb->data + p->offsetV;
case AVS_PLANAR_A:
return p->vfb->data + p->offsetA;
}
return p->vfb->data + p->offset; // Y, G
}
#endif
AVSC_API(int, avs_is_writable)(const AVS_VideoFrame * p);
// V9
AVSC_API(int, avs_is_property_writable)(const AVS_VideoFrame* p);
AVSC_API(BYTE *, avs_get_write_ptr_p)(const AVS_VideoFrame * p, int plane);
AVSC_API(void, avs_release_video_frame)(AVS_VideoFrame *);
// makes a shallow copy of a video frame
AVSC_API(AVS_VideoFrame *, avs_copy_video_frame)(AVS_VideoFrame *);
// no API for these, inline helper functions
AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p)
{return avs_get_pitch_p(p, 0);}
AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p)
{return avs_get_row_size_p(p, 0);}
AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p)
{return avs_get_height_p(p, 0);}
AVSC_INLINE const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p)
{return avs_get_read_ptr_p(p, 0);}
#ifndef AVSC_NO_DECLSPEC
// this inline function is calling an API function
AVSC_INLINE BYTE* avs_get_write_ptr(const AVS_VideoFrame * p)
{return avs_get_write_ptr_p(p, 0);}
#endif
#ifndef AVSC_NO_DECLSPEC
// this inline function is calling an API function
AVSC_INLINE void avs_release_frame(AVS_VideoFrame * f)
{avs_release_video_frame(f);}
#endif
#ifndef AVSC_NO_DECLSPEC
// this inline function is calling an API function
AVSC_INLINE AVS_VideoFrame * avs_copy_frame(AVS_VideoFrame * f)
{return avs_copy_video_frame(f);}
#endif
// Interface V8: frame properties
// AVS_Map is just a placeholder for AVSMap
typedef struct AVS_Map {
void* data;
} AVS_Map;
/////////////////////////////////////////////////////////////////////
//
// AVS_Value
//
// Treat AVS_Value as a fat pointer. That is use avs_copy_value
// and avs_release_value appropriately 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 laid out identically 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, or fu'n'ction
// for some function e'rror
short array_size;
union {
void * clip; // do not use directly, use avs_take_clip
char boolean;