├── AddGrainC ├── AddGrain.rc ├── avs │ ├── filesystem.h │ ├── minmax.h │ ├── types.h │ ├── win.h │ ├── cpuid.h │ ├── capi.h │ ├── alignment.h │ ├── posix.h │ └── config.h ├── resource.h ├── AddGrainC.sln ├── CMakeLists.txt ├── AddGrain.cpp ├── AddGrainC.vcxproj └── avisynth.h ├── README.md ├── cmake_uninstall.cmake.in ├── Documentation ├── addgrain.avs └── AddGrainC.txt ├── .gitattributes ├── .gitignore ├── CMakeLists.txt └── LICENSE /AddGrainC/AddGrain.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pinterf/AddGrainC/HEAD/AddGrainC/AddGrain.rc -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### AddGrainC ### 2 | 3 | An AviSynth plugin 4 | 5 | AddGrain generates film like grain or other effects (like rain) by adding 6 | random noise to a video clip. This noise may optionally be horizontally 7 | or vertically correlated to cause streaking. 8 | 9 | -------------------------------------------------------------------------------- /AddGrainC/avs/filesystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Snippet copied from filesystem/README.md 4 | 5 | #if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) 6 | #if __has_include() 7 | #define GHC_USE_STD_FS 8 | #include 9 | namespace fs = std::filesystem; 10 | #endif 11 | #endif 12 | #ifndef GHC_USE_STD_FS 13 | #include 14 | namespace fs = ghc::filesystem; 15 | #endif 16 | -------------------------------------------------------------------------------- /AddGrainC/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by AddGrain.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1000 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 3 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | foreach(file ${files}) 8 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 9 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 10 | exec_program( 11 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 12 | OUTPUT_VARIABLE rm_out 13 | RETURN_VALUE rm_retval 14 | ) 15 | if(NOT "${rm_retval}" STREQUAL 0) 16 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 17 | endif(NOT "${rm_retval}" STREQUAL 0) 18 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 19 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 20 | endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 21 | endforeach(file) 22 | -------------------------------------------------------------------------------- /Documentation/addgrain.avs: -------------------------------------------------------------------------------- 1 | ColorBars(width=640, height=100, pixel_type="yuv420p8") 2 | orig = last 3 | 4 | bits = 32 # set to bit depth to test 5 | c1 = orig.ConvertBits(bits) 6 | c1 = c1.addgrain_addgrain(var = 100) 7 | # uncomment for speed test 8 | #return c1 9 | #__END__ 10 | 11 | c2 = orig.addgrainc_addgrain(var = 100) 12 | 13 | c0 = orig.ScriptClip("""SubTitle("original AverageLuma =" + String(AverageLuma() / ( Bitshl(1, BitsPerComponent() - 8))))""") 14 | IF(c1.IsVideoFloat()) { 15 | c1 = c1.ScriptClip("""SubTitle("addgrain AverageLuma =" + String(AverageLuma() * 255.0 ))""") 16 | } else { 17 | c1 = c1.ScriptClip("""SubTitle("addgrain AverageLuma =" + String(AverageLuma() / ( Bitshl(1, BitsPerComponent() - 8))))""") 18 | } 19 | c2 = c2.ScriptClip("""SubTitle("addgrainc AverageLuma=" + String(AverageLuma() / ( Bitshl(1, BitsPerComponent() - 8))))""") 20 | 21 | StackVertical(c0,c1.ConvertBits(8), c2.ConvertBits(8), Diff(c1, c2)) 22 | return last 23 | 24 | Function Diff(clip src1, clip src2) 25 | { 26 | return Subtract(src1.ConvertBits(8),src2.ConvertBits(8)).Levels(120, 1, 255-120, 0, 255, coring=false) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /AddGrainC/avs/minmax.h: -------------------------------------------------------------------------------- 1 | // This program is free software; you can redistribute it and/or modify 2 | // it under the terms of the GNU General Public License as published by 3 | // the Free Software Foundation; either version 2 of the License, or 4 | // (at your option) any later version. 5 | // 6 | // This program is distributed in the hope that it will be useful, 7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | // GNU General Public License for more details. 10 | // 11 | // You should have received a copy of the GNU General Public License 12 | // along with this program; if not, write to the Free Software 13 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 14 | // http://www.gnu.org/copyleft/gpl.html . 15 | // 16 | // Linking Avisynth statically or dynamically with other modules is making a 17 | // combined work based on Avisynth. Thus, the terms and conditions of the GNU 18 | // General Public License cover the whole combination. 19 | // 20 | // As a special exception, the copyright holders of Avisynth give you 21 | // permission to link Avisynth with independent modules that communicate with 22 | // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license 23 | // terms of these independent modules, and to copy and distribute the 24 | // resulting combined work under terms of your choice, provided that 25 | // every copy of the combined work is accompanied by a complete copy of 26 | // the source code of Avisynth (the version of Avisynth used to produce the 27 | // combined work), being distributed under the terms of the GNU General 28 | // Public License plus this exception. An independent module is a module 29 | // which is not derived from or based on Avisynth, such as 3rd-party filters, 30 | // import and export plugins, or graphical user interfaces. 31 | 32 | #ifndef AVSCORE_MINMAX_H 33 | #define AVSCORE_MINMAX_H 34 | 35 | template 36 | T min(T v1, T v2) 37 | { 38 | return v1 < v2 ? v1 : v2; 39 | } 40 | 41 | template 42 | T max(T v1, T v2) 43 | { 44 | return v1 > v2 ? v1 : v2; 45 | } 46 | 47 | template 48 | T clamp(T n, T min, T max) 49 | { 50 | n = n > max ? max : n; 51 | return n < min ? min : n; 52 | } 53 | 54 | #endif // AVSCORE_MINMAX_H 55 | -------------------------------------------------------------------------------- /AddGrainC/avs/types.h: -------------------------------------------------------------------------------- 1 | // Avisynth C Interface Version 0.20 2 | // Copyright 2003 Kevin Atkinson 3 | 4 | // This program is free software; you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation; either version 2 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 17 | // http://www.gnu.org/copyleft/gpl.html . 18 | // 19 | // As a special exception, I give you permission to link to the 20 | // Avisynth C interface with independent modules that communicate with 21 | // the Avisynth C interface solely through the interfaces defined in 22 | // avisynth_c.h, regardless of the license terms of these independent 23 | // modules, and to copy and distribute the resulting combined work 24 | // under terms of your choice, provided that every copy of the 25 | // combined work is accompanied by a complete copy of the source code 26 | // of the Avisynth C interface and Avisynth itself (with the version 27 | // used to produce the combined work), being distributed under the 28 | // terms of the GNU General Public License plus this exception. An 29 | // independent module is a module which is not derived from or based 30 | // on Avisynth C Interface, such as 3rd-party filters, import and 31 | // export plugins, or graphical user interfaces. 32 | 33 | #ifndef AVS_TYPES_H 34 | #define AVS_TYPES_H 35 | 36 | // Define all types necessary for interfacing with avisynth.dll 37 | #include 38 | #include 39 | #ifdef __cplusplus 40 | #include 41 | #include 42 | #else 43 | #include 44 | #include 45 | #endif 46 | 47 | // Raster types used by VirtualDub & Avisynth 48 | typedef uint32_t Pixel32; 49 | typedef uint8_t BYTE; 50 | 51 | // Audio Sample information 52 | typedef float SFLOAT; 53 | 54 | #endif //AVS_TYPES_H 55 | -------------------------------------------------------------------------------- /AddGrainC/AddGrainC.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30002.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddGrainC", "AddGrainC.vcxproj", "{5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release ClangCl|Win32 = Release ClangCl|Win32 13 | Release ClangCl|x64 = Release ClangCl|x64 14 | Release XP|Win32 = Release XP|Win32 15 | Release XP|x64 = Release XP|x64 16 | Release|Win32 = Release|Win32 17 | Release|x64 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Debug|Win32.ActiveCfg = Debug|Win32 21 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Debug|Win32.Build.0 = Debug|Win32 22 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Debug|x64.ActiveCfg = Debug|x64 23 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Debug|x64.Build.0 = Debug|x64 24 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release ClangCl|Win32.ActiveCfg = Release ClangCl|Win32 25 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release ClangCl|Win32.Build.0 = Release ClangCl|Win32 26 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release ClangCl|x64.ActiveCfg = Release ClangCl|x64 27 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release ClangCl|x64.Build.0 = Release ClangCl|x64 28 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release XP|Win32.ActiveCfg = Release XP|Win32 29 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release XP|Win32.Build.0 = Release XP|Win32 30 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release XP|x64.ActiveCfg = Release XP|x64 31 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release XP|x64.Build.0 = Release XP|x64 32 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release|Win32.ActiveCfg = Release|Win32 33 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release|Win32.Build.0 = Release|Win32 34 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release|x64.ActiveCfg = Release|x64 35 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F}.Release|x64.Build.0 = Release|x64 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {9ED1A88F-B636-4C71-B816-0CA9FF6B75F4} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /AddGrainC/avs/win.h: -------------------------------------------------------------------------------- 1 | // This program is free software; you can redistribute it and/or modify 2 | // it under the terms of the GNU General Public License as published by 3 | // the Free Software Foundation; either version 2 of the License, or 4 | // (at your option) any later version. 5 | // 6 | // This program is distributed in the hope that it will be useful, 7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | // GNU General Public License for more details. 10 | // 11 | // You should have received a copy of the GNU General Public License 12 | // along with this program; if not, write to the Free Software 13 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 14 | // http://www.gnu.org/copyleft/gpl.html . 15 | // 16 | // Linking Avisynth statically or dynamically with other modules is making a 17 | // combined work based on Avisynth. Thus, the terms and conditions of the GNU 18 | // General Public License cover the whole combination. 19 | // 20 | // As a special exception, the copyright holders of Avisynth give you 21 | // permission to link Avisynth with independent modules that communicate with 22 | // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license 23 | // terms of these independent modules, and to copy and distribute the 24 | // resulting combined work under terms of your choice, provided that 25 | // every copy of the combined work is accompanied by a complete copy of 26 | // the source code of Avisynth (the version of Avisynth used to produce the 27 | // combined work), being distributed under the terms of the GNU General 28 | // Public License plus this exception. An independent module is a module 29 | // which is not derived from or based on Avisynth, such as 3rd-party filters, 30 | // import and export plugins, or graphical user interfaces. 31 | 32 | #ifndef AVSCORE_WIN_H 33 | #define AVSCORE_WIN_H 34 | 35 | // Whenever you need windows headers, start by including this file, then the rest. 36 | 37 | // WWUUT? We require XP now? 38 | #if !defined(NTDDI_VERSION) && !defined(_WIN32_WINNT) 39 | #define NTDDI_VERSION 0x05020000 40 | #define _WIN32_WINNT 0x0502 41 | #endif 42 | 43 | #define WIN32_LEAN_AND_MEAN 44 | #define STRICT 45 | #if !defined(NOMINMAX) 46 | #define NOMINMAX 47 | #endif 48 | 49 | #include 50 | 51 | // Provision for UTF-8 max 4 bytes per code point 52 | #define AVS_MAX_PATH MAX_PATH*4 53 | 54 | #endif // AVSCORE_WIN_H 55 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /AddGrainC/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PluginName "AddGrainC") 2 | 3 | if (NOT WIN32) 4 | string(TOLOWER "${PluginName}" PluginName) 5 | endif() 6 | 7 | set(ProjectName "${PluginName}") 8 | project(${ProjectName} LANGUAGES CXX) 9 | 10 | file(GLOB AddGrainCSources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.cpp *.h) 11 | add_library(${PluginName} SHARED ${AddGrainCSources}) 12 | 13 | #require sse2, some other plugins may need to set sse4.1 for quick msvc->gcc porting 14 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DINTEL_INTRINSICS -msse2") 15 | 16 | if (MSVC_IDE) 17 | IF(CLANG_IN_VS STREQUAL "1") 18 | # special AVX option for source files with *_avx.cpp pattern 19 | file(GLOB_RECURSE SRCS_AVX "*_avx.cpp") 20 | set_source_files_properties(${SRCS_AVX} PROPERTIES COMPILE_FLAGS " -mavx ") 21 | 22 | # special AVX2 option for source files with *_avx2.cpp pattern 23 | file(GLOB_RECURSE SRCS_AVX2 "*_avx2.cpp") 24 | set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_FLAGS " -mavx2 -mfma ") 25 | 26 | # special AVX512 option for source files with *_avx512.cpp pattern 27 | file(GLOB_RECURSE SRCS_AVX512 "*_avx512.cpp") 28 | set_source_files_properties(${SRCS_AVX512} PROPERTIES COMPILE_FLAGS " -mavx512f -mavx512bw ") 29 | ELSE() 30 | # special AVX option for source files with *_avx.cpp pattern 31 | file(GLOB_RECURSE SRCS_AVX "*_avx.cpp") 32 | set_source_files_properties(${SRCS_AVX} PROPERTIES COMPILE_FLAGS " /arch:AVX ") 33 | 34 | # special AVX2 option for source files with *_avx2.cpp pattern 35 | file(GLOB_RECURSE SRCS_AVX2 "*_avx2.cpp") 36 | set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_FLAGS " /arch:AVX2 ") 37 | 38 | # special AVX512 option for source files with *_avx512.cpp pattern 39 | file(GLOB_RECURSE SRCS_AVX512 "*_avx512.cpp") 40 | set_source_files_properties(${SRCS_AVX512} PROPERTIES COMPILE_FLAGS " /arch:AVX512 ") 41 | ENDIF() 42 | else() 43 | # special AVX option for source files with *_avx.cpp pattern 44 | file(GLOB_RECURSE SRCS_AVX "*_avx.cpp") 45 | set_source_files_properties(${SRCS_AVX} PROPERTIES COMPILE_FLAGS " -mavx ") 46 | 47 | # special AVX2 option for source files with *_avx2.cpp pattern 48 | file(GLOB_RECURSE SRCS_AVX2 "*_avx2.cpp") 49 | set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_FLAGS " -mavx2 -mfma ") 50 | 51 | # special AVX512 option for source files with *_avx512.cpp pattern 52 | file(GLOB_RECURSE SRCS_AVX512 "*_avx512.cpp") 53 | set_source_files_properties(${SRCS_AVX512} PROPERTIES COMPILE_FLAGS " -mavx512f -mavx512bw ") 54 | endif() 55 | 56 | target_link_libraries(${ProjectName}) 57 | target_include_directories(${ProjectName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) 58 | 59 | include(GNUInstallDirs) 60 | 61 | INSTALL(TARGETS ${ProjectName} 62 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/avisynth") 63 | -------------------------------------------------------------------------------- /AddGrainC/avs/cpuid.h: -------------------------------------------------------------------------------- 1 | // This program is free software; you can redistribute it and/or modify 2 | // it under the terms of the GNU General Public License as published by 3 | // the Free Software Foundation; either version 2 of the License, or 4 | // (at your option) any later version. 5 | // 6 | // This program is distributed in the hope that it will be useful, 7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | // GNU General Public License for more details. 10 | // 11 | // You should have received a copy of the GNU General Public License 12 | // along with this program; if not, write to the Free Software 13 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 14 | // http://www.gnu.org/copyleft/gpl.html . 15 | // 16 | // Linking Avisynth statically or dynamically with other modules is making a 17 | // combined work based on Avisynth. Thus, the terms and conditions of the GNU 18 | // General Public License cover the whole combination. 19 | // 20 | // As a special exception, the copyright holders of Avisynth give you 21 | // permission to link Avisynth with independent modules that communicate with 22 | // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license 23 | // terms of these independent modules, and to copy and distribute the 24 | // resulting combined work under terms of your choice, provided that 25 | // every copy of the combined work is accompanied by a complete copy of 26 | // the source code of Avisynth (the version of Avisynth used to produce the 27 | // combined work), being distributed under the terms of the GNU General 28 | // Public License plus this exception. An independent module is a module 29 | // which is not derived from or based on Avisynth, such as 3rd-party filters, 30 | // import and export plugins, or graphical user interfaces. 31 | 32 | #ifndef AVSCORE_CPUID_H 33 | #define AVSCORE_CPUID_H 34 | 35 | // For GetCPUFlags. These are backwards-compatible with those in VirtualDub. 36 | // ending with SSE4_2 37 | // For emulation see https://software.intel.com/en-us/articles/intel-software-development-emulator 38 | enum { 39 | /* oldest CPU to support extension */ 40 | CPUF_FORCE = 0x01, // N/A 41 | CPUF_FPU = 0x02, // 386/486DX 42 | CPUF_MMX = 0x04, // P55C, K6, PII 43 | CPUF_INTEGER_SSE = 0x08, // PIII, Athlon 44 | CPUF_SSE = 0x10, // PIII, Athlon XP/MP 45 | CPUF_SSE2 = 0x20, // PIV, K8 46 | CPUF_3DNOW = 0x40, // K6-2 47 | CPUF_3DNOW_EXT = 0x80, // Athlon 48 | CPUF_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2, which 49 | // only Hammer will have anyway) 50 | CPUF_SSE3 = 0x100, // PIV+, K8 Venice 51 | CPUF_SSSE3 = 0x200, // Core 2 52 | CPUF_SSE4 = 0x400, 53 | CPUF_SSE4_1 = 0x400, // Penryn, Wolfdale, Yorkfield 54 | CPUF_AVX = 0x800, // Sandy Bridge, Bulldozer 55 | CPUF_SSE4_2 = 0x1000, // Nehalem 56 | // AVS+ 57 | CPUF_AVX2 = 0x2000, // Haswell 58 | CPUF_FMA3 = 0x4000, 59 | CPUF_F16C = 0x8000, 60 | CPUF_MOVBE = 0x10000, // Big Endian move 61 | CPUF_POPCNT = 0x20000, 62 | CPUF_AES = 0x40000, 63 | CPUF_FMA4 = 0x80000, 64 | 65 | CPUF_AVX512F = 0x100000, // AVX-512 Foundation. 66 | CPUF_AVX512DQ = 0x200000, // AVX-512 DQ (Double/Quad granular) Instructions 67 | CPUF_AVX512PF = 0x400000, // AVX-512 Prefetch 68 | CPUF_AVX512ER = 0x800000, // AVX-512 Exponential and Reciprocal 69 | CPUF_AVX512CD = 0x1000000, // AVX-512 Conflict Detection 70 | CPUF_AVX512BW = 0x2000000, // AVX-512 BW (Byte/Word granular) Instructions 71 | CPUF_AVX512VL = 0x4000000, // AVX-512 VL (128/256 Vector Length) Extensions 72 | CPUF_AVX512IFMA = 0x8000000, // AVX-512 IFMA integer 52 bit 73 | CPUF_AVX512VBMI = 0x10000000,// AVX-512 VBMI 74 | }; 75 | 76 | #ifdef BUILDING_AVSCORE 77 | int GetCPUFlags(); 78 | void SetMaxCPU(int new_flags); 79 | #endif 80 | 81 | #endif // AVSCORE_CPUID_H 82 | -------------------------------------------------------------------------------- /AddGrainC/avs/capi.h: -------------------------------------------------------------------------------- 1 | // Avisynth C Interface Version 0.20 2 | // Copyright 2003 Kevin Atkinson 3 | 4 | // This program is free software; you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation; either version 2 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 17 | // http://www.gnu.org/copyleft/gpl.html . 18 | // 19 | // As a special exception, I give you permission to link to the 20 | // Avisynth C interface with independent modules that communicate with 21 | // the Avisynth C interface solely through the interfaces defined in 22 | // avisynth_c.h, regardless of the license terms of these independent 23 | // modules, and to copy and distribute the resulting combined work 24 | // under terms of your choice, provided that every copy of the 25 | // combined work is accompanied by a complete copy of the source code 26 | // of the Avisynth C interface and Avisynth itself (with the version 27 | // used to produce the combined work), being distributed under the 28 | // terms of the GNU General Public License plus this exception. An 29 | // independent module is a module which is not derived from or based 30 | // on Avisynth C Interface, such as 3rd-party filters, import and 31 | // export plugins, or graphical user interfaces. 32 | 33 | #ifndef AVS_CAPI_H 34 | #define AVS_CAPI_H 35 | 36 | #include "config.h" 37 | 38 | #ifdef AVS_POSIX 39 | // this is also defined in avs/posix.h 40 | #define __declspec(x) 41 | #endif 42 | 43 | #ifdef __cplusplus 44 | # define EXTERN_C extern "C" 45 | #else 46 | # define EXTERN_C 47 | #endif 48 | 49 | #ifdef AVS_WINDOWS 50 | #ifdef BUILDING_AVSCORE 51 | # if defined(GCC) && defined(X86_32) 52 | # define AVSC_CC 53 | # else // MSVC builds and 64-bit GCC 54 | # ifndef AVSC_USE_STDCALL 55 | # define AVSC_CC __cdecl 56 | # else 57 | # define AVSC_CC __stdcall 58 | # endif 59 | # endif 60 | #else // needed for programs that talk to AviSynth+ 61 | # ifndef AVSC_WIN32_GCC32 // see comment below 62 | # ifndef AVSC_USE_STDCALL 63 | # define AVSC_CC __cdecl 64 | # else 65 | # define AVSC_CC __stdcall 66 | # endif 67 | # else 68 | # define AVSC_CC 69 | # endif 70 | #endif 71 | # else 72 | # define AVSC_CC 73 | #endif 74 | 75 | // On 64-bit Windows, there's only one calling convention, 76 | // so there is no difference between MSVC and GCC. On 32-bit, 77 | // this isn't true. The convention that GCC needs to use to 78 | // even build AviSynth+ as 32-bit makes anything that uses 79 | // it incompatible with 32-bit MSVC builds of AviSynth+. 80 | // The AVSC_WIN32_GCC32 define is meant to provide a user 81 | // switchable way to make builds of FFmpeg to test 32-bit 82 | // GCC builds of AviSynth+ without having to screw around 83 | // with alternate headers, while still default to the usual 84 | // situation of using 32-bit MSVC builds of AviSynth+. 85 | 86 | // Hopefully, this situation will eventually be resolved 87 | // and a broadly compatible solution will arise so the 88 | // same 32-bit FFmpeg build can handle either MSVC or GCC 89 | // builds of AviSynth+. 90 | 91 | #define AVSC_INLINE static __inline 92 | 93 | #ifdef BUILDING_AVSCORE 94 | #ifdef AVS_WINDOWS 95 | # define AVSC_EXPORT __declspec(dllexport) 96 | # define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name 97 | #else 98 | # define AVSC_EXPORT EXTERN_C 99 | # define AVSC_API(ret, name) EXTERN_C ret AVSC_CC name 100 | #endif 101 | #else 102 | # define AVSC_EXPORT EXTERN_C __declspec(dllexport) 103 | # ifndef AVSC_NO_DECLSPEC 104 | # define AVSC_API(ret, name) EXTERN_C __declspec(dllimport) ret AVSC_CC name 105 | # else 106 | # define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func) 107 | # endif 108 | #endif 109 | 110 | #endif //AVS_CAPI_H 111 | -------------------------------------------------------------------------------- /AddGrainC/avs/alignment.h: -------------------------------------------------------------------------------- 1 | // Avisynth C Interface Version 0.20 2 | // Copyright 2003 Kevin Atkinson 3 | 4 | // This program is free software; you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation; either version 2 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 17 | // http://www.gnu.org/copyleft/gpl.html . 18 | // 19 | // As a special exception, I give you permission to link to the 20 | // Avisynth C interface with independent modules that communicate with 21 | // the Avisynth C interface solely through the interfaces defined in 22 | // avisynth_c.h, regardless of the license terms of these independent 23 | // modules, and to copy and distribute the resulting combined work 24 | // under terms of your choice, provided that every copy of the 25 | // combined work is accompanied by a complete copy of the source code 26 | // of the Avisynth C interface and Avisynth itself (with the version 27 | // used to produce the combined work), being distributed under the 28 | // terms of the GNU General Public License plus this exception. An 29 | // independent module is a module which is not derived from or based 30 | // on Avisynth C Interface, such as 3rd-party filters, import and 31 | // export plugins, or graphical user interfaces. 32 | 33 | #ifndef AVS_ALIGNMENT_H 34 | #define AVS_ALIGNMENT_H 35 | 36 | // Functions and macros to help work with alignment requirements. 37 | 38 | // Tells if a number is a power of two. 39 | #define IS_POWER2(n) ((n) && !((n) & ((n) - 1))) 40 | 41 | // Tells if the pointer "ptr" is aligned to "align" bytes. 42 | #define IS_PTR_ALIGNED(ptr, align) (((uintptr_t)ptr & ((uintptr_t)(align-1))) == 0) 43 | 44 | // Rounds up the number "n" to the next greater multiple of "align" 45 | #define ALIGN_NUMBER(n, align) (((n) + (align)-1) & (~((align)-1))) 46 | 47 | // Rounds up the pointer address "ptr" to the next greater multiple of "align" 48 | #define ALIGN_POINTER(ptr, align) (((uintptr_t)(ptr) + (align)-1) & (~(uintptr_t)((align)-1))) 49 | 50 | #ifdef __cplusplus 51 | 52 | #include 53 | #include 54 | #include 55 | #include "config.h" 56 | 57 | #if defined(MSVC) && _MSC_VER<1400 58 | // needed for VS2013, otherwise C++11 'alignas' works 59 | #define avs_alignas(x) __declspec(align(x)) 60 | #else 61 | // assumes C++11 support 62 | #define avs_alignas(x) alignas(x) 63 | #endif 64 | 65 | template 66 | static bool IsPtrAligned(T* ptr, size_t align) 67 | { 68 | assert(IS_POWER2(align)); 69 | return (bool)IS_PTR_ALIGNED(ptr, align); 70 | } 71 | 72 | template 73 | static T AlignNumber(T n, T align) 74 | { 75 | assert(IS_POWER2(align)); 76 | return ALIGN_NUMBER(n, align); 77 | } 78 | 79 | template 80 | static T* AlignPointer(T* ptr, size_t align) 81 | { 82 | assert(IS_POWER2(align)); 83 | return (T*)ALIGN_POINTER(ptr, align); 84 | } 85 | 86 | extern "C" 87 | { 88 | #else 89 | #include 90 | #endif // __cplusplus 91 | 92 | // Returns a new buffer that is at least the size "nbytes". 93 | // The buffer will be aligned to "align" bytes. 94 | // Returns NULL on error. On successful allocation, 95 | // the returned buffer must be freed using "avs_free". 96 | inline void* avs_malloc(size_t nbytes, size_t align) 97 | { 98 | if (!IS_POWER2(align)) 99 | return NULL; 100 | 101 | size_t offset = sizeof(void*) + align - 1; 102 | 103 | void *orig = malloc(nbytes + offset); 104 | if (orig == NULL) 105 | return NULL; 106 | 107 | void **aligned = (void**)(((uintptr_t)orig + (uintptr_t)offset) & (~(uintptr_t)(align-1))); 108 | aligned[-1] = orig; 109 | return aligned; 110 | } 111 | 112 | // Buffers allocated using "avs_malloc" must be freed 113 | // using "avs_free" instead of "free". 114 | inline void avs_free(void *ptr) 115 | { 116 | // Mirroring free()'s semantic requires us to accept NULLs 117 | if (ptr == NULL) 118 | return; 119 | 120 | free(((void**)ptr)[-1]); 121 | } 122 | 123 | #ifdef __cplusplus 124 | } // extern "C" 125 | 126 | // The point of these undef's is to force using the template functions 127 | // if we are in C++ mode. For C, the user can rely only on the macros. 128 | #undef IS_PTR_ALIGNED 129 | #undef ALIGN_NUMBER 130 | #undef ALIGN_POINTER 131 | 132 | #endif // __cplusplus 133 | 134 | #endif //AVS_ALIGNMENT_H 135 | -------------------------------------------------------------------------------- /AddGrainC/avs/posix.h: -------------------------------------------------------------------------------- 1 | // This program is free software; you can redistribute it and/or modify 2 | // it under the terms of the GNU General Public License as published by 3 | // the Free Software Foundation; either version 2 of the License, or 4 | // (at your option) any later version. 5 | // 6 | // This program is distributed in the hope that it will be useful, 7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | // GNU General Public License for more details. 10 | // 11 | // You should have received a copy of the GNU General Public License 12 | // along with this program; if not, write to the Free Software 13 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 14 | // http://www.gnu.org/copyleft/gpl.html . 15 | // 16 | // Linking Avisynth statically or dynamically with other modules is making a 17 | // combined work based on Avisynth. Thus, the terms and conditions of the GNU 18 | // General Public License cover the whole combination. 19 | // 20 | // As a special exception, the copyright holders of Avisynth give you 21 | // permission to link Avisynth with independent modules that communicate with 22 | // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license 23 | // terms of these independent modules, and to copy and distribute the 24 | // resulting combined work under terms of your choice, provided that 25 | // every copy of the combined work is accompanied by a complete copy of 26 | // the source code of Avisynth (the version of Avisynth used to produce the 27 | // combined work), being distributed under the terms of the GNU General 28 | // Public License plus this exception. An independent module is a module 29 | // which is not derived from or based on Avisynth, such as 3rd-party filters, 30 | // import and export plugins, or graphical user interfaces. 31 | 32 | #ifdef AVS_POSIX 33 | #ifndef AVSCORE_POSIX_H 34 | #define AVSCORE_POSIX_H 35 | 36 | #ifdef __cplusplus 37 | #include 38 | #endif 39 | #include 40 | #include 41 | 42 | // Define these MSVC-extension used in Avisynth 43 | #define __single_inheritance 44 | 45 | // These things don't exist in Linux 46 | #define __declspec(x) 47 | #define lstrlen strlen 48 | #define lstrcmp strcmp 49 | #define lstrcmpi strcasecmp 50 | #define _stricmp strcasecmp 51 | #define _strnicmp strncasecmp 52 | #define _strdup strdup 53 | #define SetCurrentDirectory(x) chdir(x) 54 | #define SetCurrentDirectoryW(x) chdir(x) 55 | #define GetCurrentDirectoryW(x) getcwd(x) 56 | #define _putenv putenv 57 | #define _alloca alloca 58 | 59 | // Borrowing some compatibility macros from AvxSynth, slightly modified 60 | #define UInt32x32To64(a, b) ((uint64_t)(((uint64_t)((uint32_t)(a))) * ((uint32_t)(b)))) 61 | #define Int64ShrlMod32(a, b) ((uint64_t)((uint64_t)(a) >> (b))) 62 | #define Int32x32To64(a, b) ((int64_t)(((int64_t)((long)(a))) * ((long)(b)))) 63 | 64 | #define InterlockedIncrement(x) __sync_add_and_fetch((x), 1) 65 | #define InterlockedDecrement(x) __sync_sub_and_fetch((x), 1) 66 | #define MulDiv(nNumber, nNumerator, nDenominator) (int32_t) (((int64_t) (nNumber) * (int64_t) (nNumerator) + (int64_t) ((nDenominator)/2)) / (int64_t) (nDenominator)) 67 | 68 | #ifndef TRUE 69 | #define TRUE true 70 | #endif 71 | 72 | #ifndef FALSE 73 | #define FALSE false 74 | #endif 75 | 76 | #define S_FALSE (0x00000001) 77 | #define E_FAIL (0x80004005) 78 | #define FAILED(hr) ((hr) & 0x80000000) 79 | #define SUCCEEDED(hr) (!FAILED(hr)) 80 | 81 | // Statuses copied from comments in exception.cpp 82 | #define STATUS_GUARD_PAGE_VIOLATION 0x80000001 83 | #define STATUS_DATATYPE_MISALIGNMENT 0x80000002 84 | #define STATUS_BREAKPOINT 0x80000003 85 | #define STATUS_SINGLE_STEP 0x80000004 86 | #define STATUS_ACCESS_VIOLATION 0xc0000005 87 | #define STATUS_IN_PAGE_ERROR 0xc0000006 88 | #define STATUS_INVALID_HANDLE 0xc0000008 89 | #define STATUS_NO_MEMORY 0xc0000017 90 | #define STATUS_ILLEGAL_INSTRUCTION 0xc000001d 91 | #define STATUS_NONCONTINUABLE_EXCEPTION 0xc0000025 92 | #define STATUS_INVALID_DISPOSITION 0xc0000026 93 | #define STATUS_ARRAY_BOUNDS_EXCEEDED 0xc000008c 94 | #define STATUS_FLOAT_DENORMAL_OPERAND 0xc000008d 95 | #define STATUS_FLOAT_DIVIDE_BY_ZERO 0xc000008e 96 | #define STATUS_FLOAT_INEXACT_RESULT 0xc000008f 97 | #define STATUS_FLOAT_INVALID_OPERATION 0xc0000090 98 | #define STATUS_FLOAT_OVERFLOW 0xc0000091 99 | #define STATUS_FLOAT_STACK_CHECK 0xc0000092 100 | #define STATUS_FLOAT_UNDERFLOW 0xc0000093 101 | #define STATUS_INTEGER_DIVIDE_BY_ZERO 0xc0000094 102 | #define STATUS_INTEGER_OVERFLOW 0xc0000095 103 | #define STATUS_PRIVILEGED_INSTRUCTION 0xc0000096 104 | #define STATUS_STACK_OVERFLOW 0xc00000fd 105 | 106 | // Calling convension 107 | #define __stdcall 108 | #define __cdecl 109 | 110 | #endif // AVSCORE_POSIX_H 111 | #endif // AVS_POSIX 112 | -------------------------------------------------------------------------------- /Documentation/AddGrainC.txt: -------------------------------------------------------------------------------- 1 | ** AddGrainC ** 2 | Random noise film grain generator for Avisynth+ and Avisynth 2.6 3 | Copyright (C) 2003 Tom Barry et al 4 | 5 | AddGrain generates film like grain or other effects (like rain) by adding 6 | random noise to a video clip. This noise may optionally be horizontally 7 | or vertically correlated to cause streaking. 8 | 9 | 10 | AddGrainC ( float var, float uvar, float hcorr, float vcorr, int seed, bool constant, bool sse2 ) 11 | AddGrain ( float var, float hcorr, float vcorr, float uvar, int seed, bool constant, bool sse2 ) 12 | 13 | Forum: https://forum.doom9.org/showthread.php?t=111849 14 | 15 | Requirements 16 | ================== 17 | 18 | * AviSynth+ or AviSynth 2.6 19 | * Y, planar YUV(A), planar RGB(A) video formats, RGB24/32/48/64, YUY2 20 | 21 | Parameters 22 | ================== 23 | 24 | var (1.0), uvar (0.0) 25 | The standard deviation (strength) of the luma and chroma noise, 0 is disabled. 26 | uvar does nothing in Y-only or RGB mode. 27 | 28 | hcorr (0.0), vcorr (0.0) 29 | Horizontal and vertical correlation, which causes a nifty streaking effect. 30 | Range 0.0-1.0 31 | 32 | seed (-1) 33 | Specifies a repeatable grain sequence. Set to at least 0 to use. 34 | 35 | constant (false) 36 | Specifies a constant grain pattern on every frame. 37 | 38 | sse2 (true) 39 | debug parameter, set to false for C routines 40 | 41 | 42 | AddGrain alias is left to retain compatibility with existing scripts using it. 43 | 44 | The correlation factors are actually just implemented as exponential smoothing 45 | which give a weird side affect that I did not attempt to adjust. But this means 46 | that as you increase either corr factor you will have to also increase the stddev 47 | (grain amount) in order to get the same visible amount of grain, since it is being 48 | smooth out a bit. 49 | 50 | Increase both corr factors can somewhat give clumps, or larger grain size. 51 | 52 | And there is an interesting effect with, say, AddGrain(800,0,.9) or any huge amount 53 | of strongly vertical grain. It can make a scene look like it is raining. 54 | 55 | 56 | Version History 57 | ================== 58 | 1.0 2003/06/18 Tom Barry Initial Release 59 | 1.1 2006/06/01 Foxyshadis Chroma grain + constant seed 60 | 1.2 2006/06/06 Foxyshadis Supports YUY2, RGB. Fix cache mess. 61 | 1.3 2006/06/10 Foxyshadis Crashfix, noisegen optimization 62 | 1.4 2006/08/11 Foxyshadis Constant replaces seed, seed repeatable 63 | 1.5 2010/05/07 Foxyshadis Limit the initial seed generation to fix memory issues. 64 | 1.5.1 2010/05/13 Firesledge The source code compiles on Visual C++ versions older than 2008 65 | 1.5.2 2011/10/26 Firesledge Removed the SSE2 requirement. 66 | 1.5.3 2011/10/26 Firesledge Fixed coloring and bluring in RGB24 mode. 67 | 1.5.4 2011/10/27 Firesledge Fixed bad pixels on the last line in YV12 mode when constant=true, 68 | fixed potential problems with frame width > 4096 pixels 69 | and fixed several other minor things. 70 | 1.6.0 2011/10/28 LaTo INV. Added SSE2 code (50% faster than MMX). 71 | 1.6.1 2011/10/29 LaTo INV. Automatic switch to MMX if SSE2 is not supported by the CPU. 72 | 1.7.0 2012/08/16 Firesledge Supports Y8, YV16, YV24 and YV411 colorspaces. 73 | 1.7.1 2013/11/25 Firesledge 64-bit version. 74 | ? 2014-2018 HolyWu VapourSynth port: https://github.com/HomeOfVapourSynthEvolution/VapourSynth-AddGrain 75 | ? 2019 StvG Backport to Avisynth+ 76 | Changes to 1.7.1: 77 | Support Avisynth+ high bit depth 78 | Register Avisynth+ MT mode as MT_MULTI_INSTANCE 79 | Addgrain parameter order made similar to AddGrainC: 80 | var, uvar, hcorr, vcorr, seed, constant (was: var, hcorr, vcorr, uvar, seed, constant) 81 | Removed bool "sse2" parameter 82 | Name is Addgrain 83 | Removed SIMD optimization 84 | 1.8 2020/04/09 pinterf Plugin name changed back to AddGrainC 85 | Fix output darkening (regression in VS port) 86 | Add back documentation, credits 87 | Add back SIMD optimization (SSE2, SSE4) 88 | Add back version resource 89 | 1.8.1 2020/04/09 pinterf Restore AddGrain's original parameter order and the sse2 parameter (compatibility) 90 | 1.8.2 2020/05/20 pinterf Fix SIMD code: 8/16/32 bits gave different look for the same given fixed seeds. 91 | 1.8.3 2021/03/09 pinterf Fix: possible crash for packed RGB formats 92 | 1.8.4 2022/02/15 pinterf Support YUY2 input by autoconverting internally to YV16 - instead of crash and artifacts 93 | 94 | Authors 95 | ======= 96 | Copyright (C) 2003 Tom Barry et al 97 | trbarry@trbarry.com 98 | modified by Foxyshadis 99 | foxyshadis@hotmail.com 100 | modified by Firesledge 101 | http://ldesoras.free.fr 102 | modified by LaTo INV. 103 | http://forum.doom9.org/member.php?u=131032 104 | modified by HolyWu 105 | modified by StvG 106 | modified by pinterf 107 | 108 | Also, this program is "Philanthropy-Ware". That is, if you like it and feel 109 | the need to reward or inspire the author then please feel free (but not obligated) 110 | to consider joining or donating to the Electronic Frontier Foundation. This will 111 | help keep cyber space free of barbed wire and bullsh*t. 112 | 113 | See their web page at www.eff.org 114 | 115 | -------------------------------------------------------------------------------- /AddGrainC/avs/config.h: -------------------------------------------------------------------------------- 1 | // Avisynth C Interface Version 0.20 2 | // Copyright 2003 Kevin Atkinson 3 | 4 | // This program is free software; you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation; either version 2 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 17 | // http://www.gnu.org/copyleft/gpl.html . 18 | // 19 | // As a special exception, I give you permission to link to the 20 | // Avisynth C interface with independent modules that communicate with 21 | // the Avisynth C interface solely through the interfaces defined in 22 | // avisynth_c.h, regardless of the license terms of these independent 23 | // modules, and to copy and distribute the resulting combined work 24 | // under terms of your choice, provided that every copy of the 25 | // combined work is accompanied by a complete copy of the source code 26 | // of the Avisynth C interface and Avisynth itself (with the version 27 | // used to produce the combined work), being distributed under the 28 | // terms of the GNU General Public License plus this exception. An 29 | // independent module is a module which is not derived from or based 30 | // on Avisynth C Interface, such as 3rd-party filters, import and 31 | // export plugins, or graphical user interfaces. 32 | 33 | #ifndef AVS_CONFIG_H 34 | #define AVS_CONFIG_H 35 | 36 | // Undefine this to get cdecl calling convention 37 | #define AVSC_USE_STDCALL 1 38 | 39 | // NOTE TO PLUGIN AUTHORS: 40 | // Because FRAME_ALIGN can be substantially higher than the alignment 41 | // a plugin actually needs, plugins should not use FRAME_ALIGN to check for 42 | // alignment. They should always request the exact alignment value they need. 43 | // This is to make sure that plugins work over the widest range of AviSynth 44 | // builds possible. 45 | #define FRAME_ALIGN 64 46 | 47 | #if defined(_M_AMD64) || defined(__x86_64) 48 | # define X86_64 49 | #elif defined(_M_IX86) || defined(__i386__) 50 | # define X86_32 51 | // VS2017 introduced _M_ARM64 52 | #elif defined(_M_ARM64) || defined(__aarch64__) 53 | # define ARM64 54 | #elif defined(_M_ARM) || defined(__arm__) 55 | # define ARM32 56 | #else 57 | # error Unsupported CPU architecture. 58 | #endif 59 | 60 | // VC++ LLVM-Clang-cl MinGW-Gnu 61 | // MSVC x x 62 | // MSVC_PURE x 63 | // CLANG x 64 | // GCC x 65 | 66 | #if defined(__clang__) 67 | // Check clang first. clang-cl also defines __MSC_VER 68 | // We set MSVC because they are mostly compatible 69 | # define CLANG 70 | #if defined(_MSC_VER) 71 | # define MSVC 72 | # define AVS_FORCEINLINE __attribute__((always_inline)) 73 | #else 74 | # define AVS_FORCEINLINE __attribute__((always_inline)) inline 75 | #endif 76 | #elif defined(_MSC_VER) 77 | # define MSVC 78 | # define MSVC_PURE 79 | # define AVS_FORCEINLINE __forceinline 80 | #elif defined(__GNUC__) 81 | # define GCC 82 | # define AVS_FORCEINLINE __attribute__((always_inline)) inline 83 | #else 84 | # error Unsupported compiler. 85 | # define AVS_FORCEINLINE inline 86 | # undef __forceinline 87 | # define __forceinline inline 88 | #endif 89 | 90 | #if defined(_WIN32) 91 | # define AVS_WINDOWS 92 | #elif defined(__linux__) 93 | # define AVS_LINUX 94 | # define AVS_POSIX 95 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 96 | # define AVS_BSD 97 | # define AVS_POSIX 98 | #elif defined(__APPLE__) 99 | # define AVS_MACOS 100 | # define AVS_POSIX 101 | #else 102 | # error Operating system unsupported. 103 | #endif 104 | 105 | // useful warnings disabler macros for supported compilers 106 | 107 | #if defined(_MSC_VER) 108 | #define DISABLE_WARNING_PUSH __pragma(warning( push )) 109 | #define DISABLE_WARNING_POP __pragma(warning( pop )) 110 | #define DISABLE_WARNING(warningNumber) __pragma(warning( disable : warningNumber )) 111 | 112 | #define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE DISABLE_WARNING(4101) 113 | #define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(4505) 114 | // other warnings you want to deactivate... 115 | 116 | #elif defined(__GNUC__) || defined(__clang__) 117 | #define DO_PRAGMA(X) _Pragma(#X) 118 | #define DISABLE_WARNING_PUSH DO_PRAGMA(GCC diagnostic push) 119 | #define DISABLE_WARNING_POP DO_PRAGMA(GCC diagnostic pop) 120 | #define DISABLE_WARNING(warningName) DO_PRAGMA(GCC diagnostic ignored #warningName) 121 | 122 | #define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE DISABLE_WARNING(-Wunused-variable) 123 | #define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(-Wunused-function) 124 | // other warnings you want to deactivate... 125 | 126 | #else 127 | #define DISABLE_WARNING_PUSH 128 | #define DISABLE_WARNING_POP 129 | #define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE 130 | #define DISABLE_WARNING_UNREFERENCED_FUNCTION 131 | // other warnings you want to deactivate... 132 | 133 | #endif 134 | 135 | #if defined(AVS_POSIX) 136 | #define NEW_AVSVALUE 137 | #else 138 | #define NEW_AVSVALUE 139 | #endif 140 | 141 | #if defined(AVS_WINDOWS) 142 | // Windows XP does not have proper initialization for 143 | // thread local variables. 144 | // Use workaround instead __declspec(thread) 145 | #define XP_TLS 146 | #endif 147 | 148 | #endif //AVS_CONFIG_H 149 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | [Rr]elease XP/ 22 | [Rr]elease ClangCL/ 23 | x64/ 24 | x86/ 25 | [Aa][Rr][Mm]/ 26 | [Aa][Rr][Mm]64/ 27 | bld/ 28 | [Bb]in/ 29 | [Oo]bj/ 30 | [Ll]og/ 31 | 32 | # Visual Studio 2015/2017 cache/options directory 33 | .vs/ 34 | # Uncomment if you have tasks that create the project's static files in wwwroot 35 | #wwwroot/ 36 | 37 | # Visual Studio 2017 auto generated files 38 | Generated\ Files/ 39 | 40 | # MSTest test Results 41 | [Tt]est[Rr]esult*/ 42 | [Bb]uild[Ll]og.* 43 | 44 | # NUNIT 45 | *.VisualState.xml 46 | TestResult.xml 47 | 48 | # Build Results of an ATL Project 49 | [Dd]ebugPS/ 50 | [Rr]eleasePS/ 51 | dlldata.c 52 | 53 | # Benchmark Results 54 | BenchmarkDotNet.Artifacts/ 55 | 56 | # .NET Core 57 | project.lock.json 58 | project.fragment.lock.json 59 | artifacts/ 60 | 61 | # StyleCop 62 | StyleCopReport.xml 63 | 64 | # Files built by Visual Studio 65 | *_i.c 66 | *_p.c 67 | *_h.h 68 | *.ilk 69 | *.meta 70 | *.obj 71 | *.iobj 72 | *.pch 73 | *.pdb 74 | *.ipdb 75 | *.pgc 76 | *.pgd 77 | *.rsp 78 | *.sbr 79 | *.tlb 80 | *.tli 81 | *.tlh 82 | *.tmp 83 | *.tmp_proj 84 | *_wpftmp.csproj 85 | *.log 86 | *.vspscc 87 | *.vssscc 88 | .builds 89 | *.pidb 90 | *.svclog 91 | *.scc 92 | 93 | # Chutzpah Test files 94 | _Chutzpah* 95 | 96 | # Visual C++ cache files 97 | ipch/ 98 | *.aps 99 | *.ncb 100 | *.opendb 101 | *.opensdf 102 | *.sdf 103 | *.cachefile 104 | *.VC.db 105 | *.VC.VC.opendb 106 | 107 | # Visual Studio profiler 108 | *.psess 109 | *.vsp 110 | *.vspx 111 | *.sap 112 | 113 | # Visual Studio Trace Files 114 | *.e2e 115 | 116 | # TFS 2012 Local Workspace 117 | $tf/ 118 | 119 | # Guidance Automation Toolkit 120 | *.gpState 121 | 122 | # ReSharper is a .NET coding add-in 123 | _ReSharper*/ 124 | *.[Rr]e[Ss]harper 125 | *.DotSettings.user 126 | 127 | # JustCode is a .NET coding add-in 128 | .JustCode 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # The packages folder can be ignored because of Package Restore 188 | **/[Pp]ackages/* 189 | # except build/, which is used as an MSBuild target. 190 | !**/[Pp]ackages/build/ 191 | # Uncomment if necessary however generally it will be regenerated when needed 192 | #!**/[Pp]ackages/repositories.config 193 | # NuGet v3's project.json files produces more ignorable files 194 | *.nuget.props 195 | *.nuget.targets 196 | 197 | # Microsoft Azure Build Output 198 | csx/ 199 | *.build.csdef 200 | 201 | # Microsoft Azure Emulator 202 | ecf/ 203 | rcf/ 204 | 205 | # Windows Store app package directories and files 206 | AppPackages/ 207 | BundleArtifacts/ 208 | Package.StoreAssociation.xml 209 | _pkginfo.txt 210 | *.appx 211 | 212 | # Visual Studio cache files 213 | # files ending in .cache can be ignored 214 | *.[Cc]ache 215 | # but keep track of directories ending in .cache 216 | !?*.[Cc]ache/ 217 | 218 | # Others 219 | ClientBin/ 220 | ~$* 221 | *~ 222 | *.dbmdl 223 | *.dbproj.schemaview 224 | *.jfm 225 | *.pfx 226 | *.publishsettings 227 | orleans.codegen.cs 228 | 229 | # Including strong name files can present a security risk 230 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 231 | #*.snk 232 | 233 | # Since there are multiple workflows, uncomment next line to ignore bower_components 234 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 235 | #bower_components/ 236 | 237 | # RIA/Silverlight projects 238 | Generated_Code/ 239 | 240 | # Backup & report files from converting an old project file 241 | # to a newer Visual Studio version. Backup files are not needed, 242 | # because we have git ;-) 243 | _UpgradeReport_Files/ 244 | Backup*/ 245 | UpgradeLog*.XML 246 | UpgradeLog*.htm 247 | ServiceFabricBackup/ 248 | *.rptproj.bak 249 | 250 | # SQL Server files 251 | *.mdf 252 | *.ldf 253 | *.ndf 254 | 255 | # Business Intelligence projects 256 | *.rdl.data 257 | *.bim.layout 258 | *.bim_*.settings 259 | *.rptproj.rsuser 260 | *- Backup*.rdl 261 | 262 | # Microsoft Fakes 263 | FakesAssemblies/ 264 | 265 | # GhostDoc plugin setting file 266 | *.GhostDoc.xml 267 | 268 | # Node.js Tools for Visual Studio 269 | .ntvs_analysis.dat 270 | node_modules/ 271 | 272 | # Visual Studio 6 build log 273 | *.plg 274 | 275 | # Visual Studio 6 workspace options file 276 | *.opt 277 | 278 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 279 | *.vbw 280 | 281 | # Visual Studio LightSwitch build output 282 | **/*.HTMLClient/GeneratedArtifacts 283 | **/*.DesktopClient/GeneratedArtifacts 284 | **/*.DesktopClient/ModelManifest.xml 285 | **/*.Server/GeneratedArtifacts 286 | **/*.Server/ModelManifest.xml 287 | _Pvt_Extensions 288 | 289 | # Paket dependency manager 290 | .paket/paket.exe 291 | paket-files/ 292 | 293 | # FAKE - F# Make 294 | .fake/ 295 | 296 | # JetBrains Rider 297 | .idea/ 298 | *.sln.iml 299 | 300 | # CodeRush personal settings 301 | .cr/personal 302 | 303 | # Python Tools for Visual Studio (PTVS) 304 | __pycache__/ 305 | *.pyc 306 | 307 | # Cake - Uncomment if you are using it 308 | # tools/** 309 | # !tools/packages.config 310 | 311 | # Tabs Studio 312 | *.tss 313 | 314 | # Telerik's JustMock configuration file 315 | *.jmconfig 316 | 317 | # BizTalk build output 318 | *.btp.cs 319 | *.btm.cs 320 | *.odx.cs 321 | *.xsd.cs 322 | 323 | # OpenCover UI analysis results 324 | OpenCover/ 325 | 326 | # Azure Stream Analytics local run output 327 | ASALocalRun/ 328 | 329 | # MSBuild Binary and Structured Log 330 | *.binlog 331 | 332 | # NVidia Nsight GPU debugger configuration file 333 | *.nvuser 334 | 335 | # MFractors (Xamarin productivity tool) working folder 336 | .mfractor/ 337 | 338 | # Local History for Visual Studio 339 | .localhistory/ 340 | 341 | # BeatPulse healthcheck temp database 342 | healthchecksdb -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8.2) 2 | # CMAKE_CXX_STANDARD to be set to C++17. 3 | # Visual Studio 2019 is supported from CMake 3.14.1 4 | project(AddGrainC LANGUAGES CXX) 5 | 6 | include(GNUInstallDirs) 7 | 8 | # Avoid uselessly linking to unused libraries 9 | set(CMAKE_STANDARD_LIBRARIES "" CACHE STRING "" FORCE) 10 | set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE) 11 | set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE) 12 | 13 | # We require C++17 or higher. 14 | set(CMAKE_CXX_STANDARD 17) 15 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 16 | set(CMAKE_CXX_EXTENSIONS FALSE) 17 | 18 | option(ENABLE_INTEL_SIMD "Enable SIMD intrinsics for Intel processors" ON) 19 | 20 | IF( MSVC ) # Check for Visual Studio 21 | 22 | #1800 = VS 12.0 (v120 toolset) 23 | #1900 = VS 14.0 (v140 toolset) 24 | #1910-1919 = VS 15.0 (v141 toolset) Visual Studio 2017 25 | #1920 = VS 16.0 (v142 toolset) Visual Studio 2019 26 | 27 | IF( MSVC_VERSION VERSION_LESS 1910 ) 28 | MESSAGE(FATAL_ERROR "Visual C++ 2017 or newer required.") 29 | ENDIF() 30 | IF(MSVC_IDE) 31 | message("Reported CMAKE_GENERATOR_TOOLSET is: ${CMAKE_GENERATOR_TOOLSET}") 32 | 33 | # For LLVM Clang installed separately, specify llvm or LLVM 34 | # Since Visual Studio 2019 v16.4, LLVM 9.0 is integrated, for this use Toolset: ClangCL 35 | IF(CMAKE_GENERATOR_TOOLSET STREQUAL "LLVM" OR CMAKE_GENERATOR_TOOLSET STREQUAL "llvm" OR CMAKE_GENERATOR_TOOLSET STREQUAL "ClangCL") 36 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") # hope: always 37 | message("LLVM toolset was specified via -T. Compiler ID is: ${CMAKE_CXX_COMPILER_ID}; CMAKE_CXX_COMPILER_VERSION is: ${CMAKE_CXX_COMPILER_VERSION}") 38 | # Clang; 9.0.0 39 | # These are probably not supported when clang is downloaded as a ready-made binary: CLANG_VERSION_MAJOR CLANG_VERSION_MINOR CLANG_VERSION_STRING 40 | # string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string}) 41 | if( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.1 ) 42 | MESSAGE(FATAL_ERROR "Clang 7.0.1 or newer required") # as of 2019.december actually we are using 9.0 43 | endif() 44 | endif() 45 | set(CLANG_IN_VS "1") 46 | ELSEIF(CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2") 47 | #1900 is reported 48 | message("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION}") 49 | message("May not work, try LLVM") 50 | set(CLANG_IN_VS "1") 51 | ENDIF() 52 | 53 | option(WINXP_SUPPORT "Make binaries compatible with Windows XP and Vista" OFF) 54 | if(WINXP_SUPPORT) 55 | # We want our project to also run on Windows XP 56 | # Not for LLVM: Clang stopped XP support in 2016 57 | # 1900 (VS2015) is not supported but we leave here 58 | IF(MSVC_VERSION VERSION_LESS 1910 ) 59 | IF(NOT CLANG_IN_VS STREQUAL "1") 60 | set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015 61 | # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics 62 | message("CMAKE_GENERATOR_TOOLSET is forced to: ${CMAKE_GENERATOR_TOOLSET}") 63 | add_definitions("/Zc:threadSafeInit-") 64 | ENDIF() 65 | ELSE() 66 | IF(NOT CLANG_IN_VS STREQUAL "1") 67 | set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017, also choosable for VS2019 68 | # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics 69 | message("CMAKE_GENERATOR_TOOLSET is forced to: ${CMAKE_GENERATOR_TOOLSET}") 70 | add_definitions("/Zc:threadSafeInit-") 71 | ENDIF() 72 | ENDIF() 73 | endif() 74 | ENDIF() 75 | 76 | IF(CLANG_IN_VS STREQUAL "1") 77 | #these are unknown 78 | #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions") 79 | #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions") 80 | STRING( REPLACE "/EHsc" "/EHa" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") 81 | STRING( REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 82 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-inconsistent-missing-override") 83 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override") 84 | ELSE() 85 | # Enable C++ with SEH exceptions 86 | # Avoid an obnoxious 'overrriding /EHsc with /EHa' warning when 87 | # using something other than MSBuild 88 | STRING( REPLACE "/EHsc" "/EHa" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") 89 | STRING( REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 90 | ENDIF() 91 | # Prevent VC++ from complaining about not using MS-specific functions 92 | add_definitions("/D _CRT_SECURE_NO_WARNINGS /D _SECURE_SCL=0") 93 | 94 | # Enable CRT heap debugging - only effective in debug builds 95 | add_definitions("/D _CRTDBG_MAP_ALLOC") 96 | 97 | # if missing, some modules inhibit source containing assembler/simd parts 98 | add_definitions("/D __SSE2__") 99 | 100 | # Set additional optimization flags 101 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi") 102 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi") 103 | 104 | # CPU_ARCH can be overridden with the corresponding values when using MSVC: 105 | # IA32 (disabled), 106 | # SSE (Pentium III and higher, 1999), 107 | # SSE2 (Pentium 4 and higher, 2000/2001), 108 | # AVX (Sandy Bridge and higher, 2011), 109 | # AVX2 (Haswell and higher, 2013) 110 | set(MSVC_CPU_ARCH "SSE2" CACHE STRING "Set MSVC architecture optimization level (default: SSE2)") 111 | 112 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:${MSVC_CPU_ARCH}") 113 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:${MSVC_CPU_ARCH}") 114 | 115 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 116 | # MSVC doesn't allow 64-bit builds to have their /arch set to SSE2 (no-op) or below 117 | if("${MSVC_CPU_ARCH}" MATCHES "(IA32|SSE|SSE2)") 118 | set(DELETE_THIS "/arch:${MSVC_CPU_ARCH}") 119 | message("MSVC doesn't allow x86-64 builds to define /arch:${MSVC_CPU_ARCH}. Setting will be ignored.") 120 | STRING( REPLACE "${DELETE_THIS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") 121 | STRING( REPLACE "${DELETE_THIS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 122 | endif() 123 | endif() 124 | 125 | IF(CLANG_IN_VS STREQUAL "1") 126 | # suppress other frequent but harmless/unavoidable warnings 127 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function") 128 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") 129 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder") 130 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-reorder") 131 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-value") 132 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-value") 133 | # allow per-function attributes like __attribute__((__target__("sse4.1"))) 134 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gcc-compat") 135 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-gcc-compat") 136 | ENDIF() 137 | 138 | # Enable standards-conformance mode for MSVC compilers that support this 139 | # flag (Visual C++ 2017 and later). Default. DirectShowSource will remove if needed. 140 | if (NOT (MSVC_VERSION LESS 1910)) 141 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-") 142 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /permissive-") 143 | endif() 144 | 145 | if(ENABLE_INTEL_SIMD) 146 | add_definitions("/D INTEL_INTRINSICS") 147 | endif() 148 | 149 | ELSE() 150 | # other than MSVC 151 | if(ENABLE_INTEL_SIMD) 152 | SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -DINTEL_INTRINSICS" ) 153 | endif() 154 | IF(WIN32) 155 | SET( CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-stdcall-fixup" ) 156 | ELSE() 157 | if(APPLE) 158 | # macOS uses Clang's linker, doesn't like --no-undefined 159 | SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error" ) 160 | else() 161 | if(GNUC) 162 | # make sure there are no undefined symbols 163 | SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" ) 164 | endif() 165 | endif() 166 | ENDIF() 167 | 168 | ENDIF() 169 | 170 | 171 | add_subdirectory(AddGrainC) 172 | 173 | # uninstall target 174 | configure_file( 175 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 176 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 177 | IMMEDIATE @ONLY) 178 | 179 | add_custom_target(uninstall 180 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 181 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /AddGrainC/AddGrain.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2002 Tom Barry. All rights reserved. 2 | // trbarry@trbarry.com 3 | // modified by Foxyshadis 4 | // foxyshadis@hotmail.com 5 | // modified by Firesledge 6 | // http://ldesoras.free.fr 7 | // modified by LaTo INV. 8 | // http://forum.doom9.org/member.php?u=131032 9 | // Additional modifications by HolyWu, StvG, pinterf 10 | // 11 | ///////////////////////////////////////////////////////////////////////////// 12 | // 13 | // This file is subject to the terms of the GNU General Public License as 14 | // published by the Free Software Foundation. A copy of this license is 15 | // included with this software distribution in the file COPYING. If you 16 | // do not have a copy, you may obtain a copy by writing to the Free 17 | // Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 18 | // 19 | // This software is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | // GNU General Public License for more details 23 | // 24 | // Also, this program is "Philanthropy-Ware". That is, if you like it and 25 | // feel the need to reward or inspire the author then please feel free (but 26 | // not obligated) to consider joining or donating to the Electronic Frontier 27 | // Foundation. This will help keep cyber space free of barbed wire and bullsh*t. 28 | // 29 | ///////////////////////////////////////////////////////////////////////////// 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "avisynth.h" 41 | 42 | #ifdef INTEL_INTRINSICS 43 | #include "emmintrin.h" 44 | #include "smmintrin.h" // sse4 45 | #endif 46 | 47 | #define VS_RESTRICT __restrict 48 | 49 | // max # of noise planes 50 | static constexpr int MAXP = 2; 51 | 52 | // offset in pixels of the fake plane MAXP relative to plane MAXP-1 53 | static constexpr int OFFSET_FAKEPLANE = 32; 54 | 55 | class AddGrain : public GenericVideoFilter { 56 | int64_t idum; 57 | int nStride[MAXP], nHeight[MAXP], nSize[MAXP], storedFrames; 58 | std::vector pNoiseSeeds; 59 | std::vector pN[MAXP]; 60 | std::vector pNF[MAXP]; 61 | float _var, _uvar, _hcorr, _vcorr; 62 | int _seed; 63 | bool _constant; 64 | bool _simd; 65 | 66 | void setRand(int* plane, int* noiseOffs, const int frameNumber); 67 | #ifdef INTEL_INTRINSICS 68 | void updateFrame_8_SSE2(uint8_t* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int bits_per_pixel); 69 | void updateFrame_16_SSE4(uint16_t* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int bits_per_pixel); 70 | void updateFrame_32_SSE2(float* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int bits_per_pixel); 71 | #endif 72 | template 73 | void updateFrame(T1* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int bits_per_pixel); 74 | 75 | public: 76 | AddGrain(PClip _child, float var, float uvar, float hcorr, float vcorr, int seed, bool constant, bool simd, IScriptEnvironment* env); 77 | PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); 78 | int __stdcall SetCacheHints(int cachehints, int frame_range) 79 | { 80 | return cachehints == CACHE_GET_MTMODE ? MT_MULTI_INSTANCE : 0; 81 | } 82 | }; 83 | 84 | // for gcc: outside the class 85 | template<> 86 | void AddGrain::updateFrame(float* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int); 87 | 88 | static inline int64_t fastUniformRandL(int64_t* idum) noexcept { 89 | return *idum = 1664525LL * (*idum) + 1013904223LL; 90 | } 91 | 92 | // very fast & reasonably random 93 | static inline float fastUniformRandF(int64_t* idum) noexcept { 94 | // work with 32-bit IEEE floating point only! 95 | fastUniformRandL(idum); 96 | const uint64_t itemp = 0x3f800000 | (0x007fffff & *idum); 97 | return *reinterpret_cast(&itemp) - 1.f; 98 | } 99 | 100 | static inline float gaussianRand(bool* iset, float* gset, int64_t* idum) noexcept { 101 | float fac, rsq, v1, v2; 102 | 103 | // return saved second 104 | if (*iset) { 105 | *iset = false; 106 | return *gset; 107 | } 108 | 109 | do { 110 | v1 = 2.f * fastUniformRandF(idum) - 1.f; 111 | v2 = 2.f * fastUniformRandF(idum) - 1.f; 112 | rsq = v1 * v1 + v2 * v2; 113 | } while (rsq >= 1.f || rsq == 0.f); 114 | 115 | fac = std::sqrt(-2.f * std::log(rsq) / rsq); 116 | 117 | // function generates two values every iteration, so save one for later 118 | *gset = v1 * fac; 119 | *iset = true; 120 | 121 | return v2 * fac; 122 | } 123 | 124 | static inline float gaussianRand(const float mean, const float variance, bool* iset, float* gset, int64_t* idum) noexcept { 125 | return (variance == 0.f) ? mean : gaussianRand(iset, gset, idum) * std::sqrt(variance) + mean; 126 | } 127 | 128 | // on input, plane is the frame plane index (if applicable, 0 otherwise), and on output, it contains the selected noise plane 129 | void AddGrain::setRand(int* plane, int* noiseOffs, const int frameNumber) { 130 | if (_constant) { 131 | // force noise to be identical every frame 132 | if (*plane >= MAXP) { 133 | *plane = MAXP - 1; 134 | *noiseOffs = OFFSET_FAKEPLANE; 135 | } 136 | } 137 | else { 138 | // pull seed back out, to keep cache happy 139 | const int seedIndex = frameNumber % storedFrames; 140 | const int p0 = pNoiseSeeds[seedIndex]; 141 | 142 | if (*plane == 0) { 143 | idum = p0; 144 | } 145 | else { 146 | idum = pNoiseSeeds[(int64_t)seedIndex + storedFrames]; 147 | if (*plane == 2) { 148 | // the trick to needing only 2 planes ^.~ 149 | idum ^= p0; 150 | (*plane)--; 151 | } 152 | } 153 | 154 | // start noise at random qword in top half of noise area 155 | *noiseOffs = static_cast(fastUniformRandF(&idum) * nSize[*plane] / MAXP) & 0xfffffff8; 156 | } 157 | 158 | assert(*plane >= 0); 159 | assert(*plane < MAXP); 160 | assert(*noiseOffs >= 0); 161 | assert(*noiseOffs < nSize[*plane]); // minimal check 162 | } 163 | 164 | #ifdef INTEL_INTRINSICS 165 | 166 | #if defined(GCC) || defined(CLANG) 167 | __attribute__((__target__("sse2"))) 168 | #endif 169 | void AddGrain::updateFrame_8_SSE2(uint8_t* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int bits_per_pixel) { 170 | const int16_t* pNW = pN[noisePlane].data() + noiseOffs; 171 | const size_t nstride = nStride[noisePlane]; 172 | 173 | // assert(noiseOffs + (nStride[noisePlane] >> 4) * (height - 1) + (stride * 16) <= nSize[noisePlane]); 174 | 175 | const auto sign_mask = _mm_set1_epi8((char)0x80); // 0x80 176 | 177 | for (int y = 0; y < height; y++) { 178 | for (int x = 0; x < width; x += 16) { 179 | auto src = _mm_load_si128(reinterpret_cast(dstp + x)); 180 | auto noise_lo = _mm_loadu_si128(reinterpret_cast(pNW + x)); // signed 16 181 | auto noise_hi = _mm_loadu_si128(reinterpret_cast(pNW + x + 8)); 182 | auto noise = _mm_packs_epi16(noise_lo, noise_hi); 183 | auto src_signed = _mm_add_epi8(src, sign_mask); 184 | auto sum = _mm_adds_epi8(noise, src_signed); 185 | auto result = _mm_add_epi8(sum, sign_mask); 186 | _mm_store_si128(reinterpret_cast<__m128i*>(dstp + x), result); 187 | } 188 | dstp += stride; 189 | pNW += nstride; 190 | } 191 | } 192 | 193 | #if defined(GCC) || defined(CLANG) 194 | __attribute__((__target__("sse4.1"))) 195 | #endif 196 | void AddGrain::updateFrame_16_SSE4(uint16_t* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int bits_per_pixel) { 197 | const int16_t* pNW = pN[noisePlane].data() + noiseOffs; 198 | const size_t nstride = nStride[noisePlane]; 199 | 200 | // assert(noiseOffs + (nStride[noisePlane] >> 4) * (height - 1) + (stride * 16) <= nSize[noisePlane]); 201 | 202 | auto sign_mask = _mm_set1_epi16((short)0x8000); 203 | 204 | const int max_pixel_value = (1 << bits_per_pixel) - 1; 205 | auto limit = _mm_set1_epi16(max_pixel_value); 206 | 207 | for (int y = 0; y < height; y++) { 208 | for (int x = 0; x < width * sizeof(uint16_t); x += 16) { 209 | auto src = _mm_load_si128(reinterpret_cast((uint8_t *)dstp + x)); 210 | auto noise = _mm_loadu_si128(reinterpret_cast((uint8_t*)pNW + x)); // signed 16 211 | auto src_signed = _mm_add_epi16(src, sign_mask); 212 | auto sum = _mm_adds_epi16(noise, src_signed); 213 | sum = _mm_add_epi16(sum, sign_mask); 214 | auto result = _mm_min_epu16(sum, limit); // for exact 16 bit it's not needed 215 | _mm_store_si128(reinterpret_cast<__m128i*>((uint8_t*)dstp + x), result); 216 | } 217 | dstp += stride; 218 | pNW += nstride; 219 | } 220 | } 221 | 222 | #if defined(GCC) || defined(CLANG) 223 | __attribute__((__target__("sse2"))) 224 | #endif 225 | void AddGrain::updateFrame_32_SSE2(float* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int) { 226 | const float* pNW = pNF[noisePlane].data() + noiseOffs; 227 | const size_t nstride = nStride[noisePlane]; 228 | 229 | // assert(noiseOffs + (nStride[noisePlane] >> 4) * (height - 1) + (stride * 16) <= nSize[noisePlane]); 230 | 231 | for (int y = 0; y < height; y++) { 232 | for (int x = 0; x < width * sizeof(float); x += 16) { 233 | auto src = _mm_load_ps(reinterpret_cast((uint8_t*)dstp + x)); 234 | auto noise = _mm_loadu_ps(reinterpret_cast((uint8_t*)pNW + x)); // signed 16 235 | auto result = _mm_add_ps(noise, src); 236 | _mm_store_ps(reinterpret_cast((uint8_t*)dstp + x), result); 237 | } 238 | dstp += stride; 239 | pNW += nstride; 240 | } 241 | } 242 | #endif // #ifdef INTEL_INTRINSICS 243 | 244 | template 245 | void AddGrain::updateFrame(T1* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int bits_per_pixel) { 246 | const int upper = 1 << bits_per_pixel; 247 | const int16_t* pNW = pN[noisePlane].data() + noiseOffs; 248 | 249 | // assert(noiseOffs + (nStride[noisePlane] >> 4) * (height - 1) + (stride * 16) <= nSize[noisePlane]); 250 | 251 | for (int y = 0; y < height; y++) { 252 | for (int x = 0; x < width; x++) { 253 | if constexpr (sizeof(T1) == 1) 254 | dstp[x] = (T1)(std::min(std::max(dstp[x] + pNW[x], 0), 255)); 255 | else 256 | dstp[x] = (T1)(std::min(std::max(dstp[x] + pNW[x], 0), upper)); 257 | } 258 | dstp += stride; 259 | pNW += nStride[noisePlane]; 260 | } 261 | } 262 | 263 | template<> 264 | void AddGrain::updateFrame(float* VS_RESTRICT dstp, const int width, const int height, const int stride, const int noisePlane, const int noiseOffs, const int) { 265 | const float* pNW = pNF[noisePlane].data() + noiseOffs; 266 | //assert(noiseOffs + (nStride[noisePlane] >> 4) * (height - 1) + (stride * 16) <= nSize[noisePlane]); 267 | 268 | for (int y = 0; y < height; y++) { 269 | for (int x = 0; x < width; x++) 270 | dstp[x] += pNW[x]; 271 | 272 | dstp += stride; 273 | pNW += nStride[noisePlane]; 274 | } 275 | } 276 | 277 | AddGrain::AddGrain(PClip _child, float var, float uvar, float hcorr, float vcorr, int seed, bool constant, bool simd, IScriptEnvironment* env) 278 | : GenericVideoFilter(_child), _var(var), _uvar(uvar), _hcorr(hcorr), _vcorr(vcorr), _seed(seed), _constant(constant), _simd(simd) 279 | { 280 | bool iset = false; 281 | float gset; 282 | 283 | if (_seed < 0) 284 | _seed = std::time(nullptr); // init random 285 | idum = _seed; 286 | 287 | int planesNoise = 1; 288 | if(vi.IsRGB() && !vi.IsPlanar()) 289 | // packed RGB: width is GetRowSize, which is 3x (RGB24) or 4x (RGB32) as large 290 | nStride[0] = (vi.width * vi.NumComponents() + 15) & ~15; // first plane 291 | else 292 | nStride[0] = (vi.width + 15) & ~15; // first plane 293 | nHeight[0] = vi.height; 294 | if (vi.IsY()) { 295 | _uvar = 0.f; 296 | } 297 | else if (vi.IsRGB()) { 298 | _uvar = _var; 299 | } 300 | else { 301 | planesNoise = 2; 302 | nStride[1] = ((vi.width >> vi.GetPlaneWidthSubsampling(PLANAR_U)) + 15) & ~15; // second and third plane 303 | nHeight[1] = vi.height >> vi.GetPlaneHeightSubsampling(PLANAR_U); 304 | } 305 | 306 | storedFrames = std::min(vi.num_frames, 256); 307 | pNoiseSeeds.resize((int64_t)storedFrames * planesNoise); 308 | auto pns = pNoiseSeeds.begin(); 309 | 310 | float nRep[] = { 2.f, 2.f }; 311 | if (_constant) 312 | nRep[0] = nRep[1] = 1.f; 313 | 314 | const float pvar[] = { _var, _uvar }; 315 | std::vector lastLine(nStride[0]); // assume plane 0 is the widest one 316 | const float mean = 0.f; 317 | 318 | const int bits_per_pixel = vi.BitsPerComponent(); 319 | const float noise_scale = bits_per_pixel == 32 ? 1 / 255.f : (float)(1 << (bits_per_pixel - 8)); 320 | 321 | for (int plane = 0; plane < planesNoise; plane++) 322 | { 323 | int h = static_cast(std::ceil(nHeight[plane] * nRep[plane])); 324 | if (planesNoise == 2 && plane == 1) { 325 | // fake plane needs at least one more row, and more if the rows are too small. round to the upper number 326 | h += (OFFSET_FAKEPLANE + nStride[plane] - 1) / nStride[plane]; 327 | } 328 | nSize[plane] = nStride[plane] * h; 329 | 330 | // allocate space for noise 331 | if (vi.BitsPerComponent() != 32) 332 | pN[plane].resize(nSize[plane]); 333 | else 334 | pNF[plane].resize(nSize[plane]); 335 | 336 | for (int x = 0; x < nStride[plane]; x++) 337 | lastLine[x] = gaussianRand(mean, pvar[plane], &iset, &gset, &idum); // things to vertically smooth against 338 | 339 | for (int y = 0; y < h; y++) { 340 | if (vi.BitsPerComponent() != 32) { 341 | auto pNW = pN[plane].begin() + (int64_t)nStride[plane] * y; 342 | float lastr = gaussianRand(mean, pvar[plane], &iset, &gset, &idum); // something to horiz smooth against 343 | 344 | for (int x = 0; x < nStride[plane]; x++) { 345 | float r = gaussianRand(mean, pvar[plane], &iset, &gset, &idum); 346 | 347 | r = lastr * _hcorr + r * (1.f - _hcorr); // horizontal correlation 348 | lastr = r; 349 | 350 | r = lastLine[x] * _vcorr + r * (1.f - _vcorr); // vert corr 351 | lastLine[x] = r; 352 | 353 | *pNW++ = static_cast(std::round(r * noise_scale)); // set noise block 354 | } 355 | } 356 | else { 357 | auto pNW = pNF[plane].begin() + (int64_t)nStride[plane] * y; 358 | float lastr = gaussianRand(mean, pvar[plane], &iset, &gset, &idum); // something to horiz smooth against 359 | 360 | for (int x = 0; x < nStride[plane]; x++) { 361 | float r = gaussianRand(mean, pvar[plane], &iset, &gset, &idum); 362 | 363 | r = lastr * _hcorr + r * (1.f - _hcorr); // horizontal correlation 364 | lastr = r; 365 | 366 | r = lastLine[x] * _vcorr + r * (1.f - _vcorr); // vert corr 367 | lastLine[x] = r; 368 | 369 | *pNW++ = r * noise_scale; // set noise block 370 | } 371 | } 372 | } 373 | 374 | for (int x = storedFrames; x > 0; x--) 375 | *pns++ = fastUniformRandL(&idum) & 0xff; // insert seed, to keep cache happy 376 | } 377 | } 378 | 379 | 380 | PVideoFrame AddGrain::GetFrame(int n, IScriptEnvironment* env) { 381 | PVideoFrame src = child->GetFrame(n, env); 382 | env->MakeWritable(&src); 383 | 384 | int plane; 385 | int noiseOffs = 0; 386 | 387 | const int bits_per_pixel = vi.BitsPerComponent(); 388 | 389 | #ifdef INTEL_INTRINSICS 390 | const bool sse2 = _simd && !!(env->GetCPUFlags() & CPUF_SSE2); 391 | const bool sse41 = _simd && !!(env->GetCPUFlags() & CPUF_SSE4_1); 392 | #endif 393 | 394 | int planes_y[4] = { PLANAR_Y, PLANAR_U, PLANAR_V, PLANAR_A }; 395 | int planes_r[4] = { PLANAR_G, PLANAR_B, PLANAR_R, PLANAR_A }; 396 | int* planes = (vi.IsPlanarRGB() || vi.IsPlanarRGBA()) ? planes_r : planes_y; 397 | 398 | if (_var > 0.f) 399 | { 400 | const int widthY = src->GetRowSize(planes[0]) / vi.ComponentSize(); 401 | const int heightY = src->GetHeight(planes[0]); 402 | const int strideY = src->GetPitch(planes[0]); 403 | uint8_t* dstpY = src->GetWritePtr(planes[0]); 404 | 405 | plane = 0; 406 | int noisePlane = plane; 407 | 408 | setRand(&noisePlane, &noiseOffs, n); // seeds randomness w/ plane & frame 409 | 410 | if (vi.ComponentSize() == 1) { 411 | #ifdef INTEL_INTRINSICS 412 | if (sse2) 413 | updateFrame_8_SSE2(dstpY, widthY, heightY, strideY, noisePlane, noiseOffs, bits_per_pixel); 414 | else 415 | #endif 416 | updateFrame(dstpY, widthY, heightY, strideY, noisePlane, noiseOffs, bits_per_pixel); 417 | } 418 | else if (vi.ComponentSize() == 2) { 419 | #ifdef INTEL_INTRINSICS 420 | if (sse41) 421 | updateFrame_16_SSE4(reinterpret_cast(dstpY), widthY, heightY, strideY / 2, noisePlane, noiseOffs, bits_per_pixel); 422 | else 423 | #endif 424 | updateFrame(reinterpret_cast(dstpY), widthY, heightY, strideY / 2, noisePlane, noiseOffs, bits_per_pixel); 425 | } 426 | else 427 | #ifdef INTEL_INTRINSICS 428 | if (sse2) 429 | updateFrame_32_SSE2(reinterpret_cast(dstpY), widthY, heightY, strideY / 4, noisePlane, noiseOffs, bits_per_pixel); 430 | else 431 | #endif 432 | updateFrame(reinterpret_cast(dstpY), widthY, heightY, strideY / 4, noisePlane, noiseOffs, bits_per_pixel); 433 | } 434 | 435 | if (_uvar > 0.f) 436 | { 437 | const int widthUV = src->GetRowSize(planes[1]) / vi.ComponentSize(); 438 | const int heightUV = src->GetHeight(planes[1]); 439 | const int strideUV = src->GetPitch(planes[1]); 440 | uint8_t* dstpU = src->GetWritePtr(planes[1]); 441 | uint8_t* dstpV = src->GetWritePtr(planes[2]); 442 | 443 | plane = 1; 444 | int noisePlane = (vi.IsRGB()) ? 0 : plane; 445 | 446 | setRand(&noisePlane, &noiseOffs, n); // seeds randomness w/ plane & frame 447 | 448 | if (vi.ComponentSize() == 1) { 449 | #ifdef INTEL_INTRINSICS 450 | if (sse2) 451 | updateFrame_8_SSE2(dstpU, widthUV, heightUV, strideUV, noisePlane, noiseOffs, bits_per_pixel); 452 | else 453 | #endif 454 | updateFrame(dstpU, widthUV, heightUV, strideUV, noisePlane, noiseOffs, bits_per_pixel); 455 | } 456 | else if (vi.ComponentSize() == 2) { 457 | #ifdef INTEL_INTRINSICS 458 | if (sse41) 459 | updateFrame_16_SSE4(reinterpret_cast(dstpU), widthUV, heightUV, strideUV / 2, noisePlane, noiseOffs, bits_per_pixel); 460 | else 461 | #endif 462 | updateFrame(reinterpret_cast(dstpU), widthUV, heightUV, strideUV / 2, noisePlane, noiseOffs, bits_per_pixel); 463 | } 464 | else 465 | #ifdef INTEL_INTRINSICS 466 | if (sse2) 467 | updateFrame_32_SSE2(reinterpret_cast(dstpU), widthUV, heightUV, strideUV / 4, noisePlane, noiseOffs, bits_per_pixel); 468 | else 469 | #endif 470 | updateFrame(reinterpret_cast(dstpU), widthUV, heightUV, strideUV / 4, noisePlane, noiseOffs, bits_per_pixel); 471 | 472 | plane = 2; 473 | noisePlane = (vi.IsRGB()) ? 0 : plane; 474 | 475 | setRand(&noisePlane, &noiseOffs, n); // seeds randomness w/ plane & frame 476 | 477 | if (vi.ComponentSize() == 1) { 478 | #ifdef INTEL_INTRINSICS 479 | if (sse2) 480 | updateFrame_8_SSE2(dstpV, widthUV, heightUV, strideUV, noisePlane, noiseOffs, bits_per_pixel); 481 | else 482 | #endif 483 | updateFrame(dstpV, widthUV, heightUV, strideUV, noisePlane, noiseOffs, bits_per_pixel); 484 | } 485 | else if (vi.ComponentSize() == 2) { 486 | #ifdef INTEL_INTRINSICS 487 | if (sse41) 488 | updateFrame_16_SSE4(reinterpret_cast(dstpV), widthUV, heightUV, strideUV / 2, noisePlane, noiseOffs, bits_per_pixel); 489 | else 490 | #endif 491 | updateFrame(reinterpret_cast(dstpV), widthUV, heightUV, strideUV / 2, noisePlane, noiseOffs, bits_per_pixel); 492 | } 493 | else 494 | #ifdef INTEL_INTRINSICS 495 | if (sse2) 496 | updateFrame_32_SSE2(reinterpret_cast(dstpV), widthUV, heightUV, strideUV / 4, noisePlane, noiseOffs, bits_per_pixel); 497 | else 498 | #endif 499 | updateFrame(reinterpret_cast(dstpV), widthUV, heightUV, strideUV / 4, noisePlane, noiseOffs, bits_per_pixel); 500 | } 501 | 502 | return src; 503 | 504 | } 505 | 506 | AVSValue __cdecl Create_AddGrain(AVSValue args, void* user_data, IScriptEnvironment* env) 507 | { 508 | /* VapourSynth order 509 | const float var = args[1].AsFloatf(1); 510 | const float uvar = args[2].AsFloatf(0); 511 | const float hcorr = args[3].AsFloatf(0); 512 | const float vcorr = args[4].AsFloatf(0); 513 | */ 514 | // original order, different from AddGrainC 515 | const float var = args[1].AsFloatf(1); 516 | const float uvar = args[4].AsFloatf(0); 517 | const float hcorr = args[2].AsFloatf(0); 518 | const float vcorr = args[3].AsFloatf(0); 519 | 520 | #ifdef INTEL_INTRINSICS 521 | const bool sse2 = args[7].AsBool(true); 522 | #else 523 | const bool sse2 = false; 524 | #endif 525 | 526 | if ((hcorr) < 0.f || (hcorr) > 1.f || (vcorr) < 0.f || (vcorr) > 1.f) { 527 | env->ThrowError("AddGrain: hcorr and vcorr must be between 0.0 and 1.0 (inclusive)"); 528 | } 529 | 530 | PClip clip = args[0].AsClip(); 531 | const VideoInfo& vi = clip->GetVideoInfo(); 532 | 533 | // yuy2 is autoconverted to/from YV16. 534 | bool need_convert_yuy2 = vi.IsYUY2(); 535 | 536 | if (need_convert_yuy2) { 537 | AVSValue new_args[1] = { clip }; 538 | clip = env->Invoke("ConvertToYV16", AVSValue(new_args, 1)).AsClip(); 539 | } 540 | 541 | AVSValue result = new AddGrain(clip, var, uvar, hcorr, vcorr, args[5].AsInt(-1), args[6].AsBool(false), sse2, env); 542 | 543 | if (need_convert_yuy2) { 544 | AVSValue new_args[1] = { result }; 545 | result = env->Invoke("ConvertToYUY2", AVSValue(new_args, 1)).AsClip(); 546 | } 547 | 548 | return result; 549 | } 550 | 551 | AVSValue __cdecl Create_AddGrainC(AVSValue args, void* user_data, IScriptEnvironment* env) 552 | { 553 | const float var = args[1].AsFloatf(1); 554 | const float uvar = args[2].AsFloatf(0); 555 | const float hcorr = args[3].AsFloatf(0); 556 | const float vcorr = args[4].AsFloatf(0); 557 | 558 | #ifdef INTEL_INTRINSICS 559 | const bool sse2 = args[7].AsBool(true); 560 | #else 561 | const bool sse2 = false; 562 | #endif 563 | 564 | if ((hcorr) < 0.f || (hcorr) > 1.f || (vcorr) < 0.f || (vcorr) > 1.f) { 565 | env->ThrowError("AddGrainC: hcorr and vcorr must be between 0.0 and 1.0 (inclusive)"); 566 | } 567 | 568 | PClip clip = args[0].AsClip(); 569 | const VideoInfo& vi = clip->GetVideoInfo(); 570 | 571 | // yuy2 is autoconverted to/from YV16. 572 | bool need_convert_yuy2 = vi.IsYUY2(); 573 | 574 | if (need_convert_yuy2) { 575 | AVSValue new_args[1] = { clip }; 576 | clip = env->Invoke("ConvertToYV16", AVSValue(new_args, 1)).AsClip(); 577 | } 578 | 579 | AVSValue result = new AddGrain(clip, var, uvar, hcorr, vcorr, args[5].AsInt(-1), args[6].AsBool(false), sse2, env); 580 | 581 | if (need_convert_yuy2) { 582 | AVSValue new_args[1] = { result }; 583 | result = env->Invoke("ConvertToYUY2", AVSValue(new_args, 1)).AsClip(); 584 | } 585 | 586 | return result; 587 | } 588 | 589 | const AVS_Linkage* AVS_linkage; 590 | 591 | extern "C" __declspec(dllexport) 592 | const char* __stdcall AvisynthPluginInit3(IScriptEnvironment * env, const AVS_Linkage* const vectors) 593 | { 594 | AVS_linkage = vectors; 595 | env->AddFunction("AddGrain", "c[var]f[hcorr]f[vcorr]f[uvar]f[seed]i[constant]b[sse2]b", Create_AddGrain, NULL); 596 | env->AddFunction("AddGrainC", "c[var]f[uvar]f[hcorr]f[vcorr]f[seed]i[constant]b[sse2]b", Create_AddGrainC, NULL); 597 | return "`AddGrainC' Add some correlated color gaussian noise"; 598 | 599 | } -------------------------------------------------------------------------------- /AddGrainC/AddGrainC.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release ClangCl 14 | Win32 15 | 16 | 17 | Release ClangCl 18 | x64 19 | 20 | 21 | Release XP 22 | Win32 23 | 24 | 25 | Release XP 26 | x64 27 | 28 | 29 | Release 30 | Win32 31 | 32 | 33 | Release 34 | x64 35 | 36 | 37 | 38 | {5848CFCB-281C-4FFB-B552-60CF9A8C6B3F} 39 | AddGrainC 40 | 10.0 41 | 42 | 43 | 44 | DynamicLibrary 45 | v142 46 | false 47 | MultiByte 48 | 49 | 50 | DynamicLibrary 51 | ClangCL 52 | false 53 | MultiByte 54 | 55 | 56 | DynamicLibrary 57 | v141_xp 58 | false 59 | MultiByte 60 | 61 | 62 | DynamicLibrary 63 | v142 64 | false 65 | MultiByte 66 | 67 | 68 | DynamicLibrary 69 | v142 70 | false 71 | MultiByte 72 | 73 | 74 | DynamicLibrary 75 | ClangCL 76 | false 77 | MultiByte 78 | 79 | 80 | DynamicLibrary 81 | v141_xp 82 | false 83 | MultiByte 84 | 85 | 86 | DynamicLibrary 87 | v142 88 | false 89 | MultiByte 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 | <_ProjectFileVersion>11.0.60610.1 129 | 130 | 131 | $(Configuration)\$(Platform)\ 132 | $(Configuration)\$(Platform)\ 133 | true 134 | 135 | 136 | $(Configuration)\$(Platform)\ 137 | $(Configuration)\$(Platform)\ 138 | false 139 | 140 | 141 | $(Configuration)\$(Platform)\ 142 | $(Configuration)\$(Platform)\ 143 | false 144 | 145 | 146 | $(Configuration)\$(Platform)\ 147 | $(Configuration)\$(Platform)\ 148 | false 149 | 150 | 151 | $(Configuration)\$(Platform)\ 152 | $(Configuration)\$(Platform)\ 153 | true 154 | 155 | 156 | $(Configuration)\$(Platform)\ 157 | $(Configuration)\$(Platform)\ 158 | false 159 | 160 | 161 | $(Configuration)\$(Platform)\ 162 | $(Configuration)\$(Platform)\ 163 | false 164 | 165 | 166 | $(Configuration)\$(Platform)\ 167 | $(Configuration)\$(Platform)\ 168 | false 169 | 170 | 171 | 172 | _DEBUG;%(PreprocessorDefinitions) 173 | true 174 | true 175 | Win32 176 | 177 | 178 | 179 | Disabled 180 | Default 181 | false 182 | Neither 183 | WIN32;INTEL_INTRINSICS;_DEBUG;_WINDOWS;_USRDLL;ADDGRAINC_EXPORTS;%(PreprocessorDefinitions) 184 | false 185 | Sync 186 | Default 187 | false 188 | MultiThreadedDebug 189 | Default 190 | true 191 | StreamingSIMDExtensions 192 | 193 | 194 | true 195 | Level3 196 | true 197 | ProgramDatabase 198 | true 199 | stdcpp17 200 | 201 | 202 | _DEBUG;%(PreprocessorDefinitions) 203 | 0x0409 204 | 205 | 206 | true 207 | true 208 | MachineX86 209 | Console 210 | 211 | 212 | true 213 | 214 | 215 | 216 | 217 | NDEBUG;%(PreprocessorDefinitions) 218 | true 219 | true 220 | Win32 221 | 222 | 223 | 224 | MaxSpeed 225 | AnySuitable 226 | true 227 | Speed 228 | true 229 | true 230 | WIN32;INTEL_INTRINSICS;NDEBUG;_WINDOWS;_USRDLL;ADDGRAINC_EXPORTS;%(PreprocessorDefinitions) 231 | true 232 | Sync 233 | MultiThreadedDLL 234 | Default 235 | false 236 | true 237 | StreamingSIMDExtensions 238 | Fast 239 | $(IntDir) 240 | $(IntDir) 241 | $(IntDir) 242 | Level3 243 | true 244 | true 245 | stdcpp17 246 | 247 | 248 | NDEBUG;%(PreprocessorDefinitions) 249 | 0x0409 250 | 251 | 252 | $(IntDir)AddGrainC.dll 253 | true 254 | true 255 | true 256 | MachineX86 257 | true 258 | Console 259 | 260 | 261 | true 262 | 263 | 264 | 265 | 266 | NDEBUG;%(PreprocessorDefinitions) 267 | true 268 | true 269 | Win32 270 | 271 | 272 | 273 | 274 | MaxSpeed 275 | AnySuitable 276 | true 277 | Speed 278 | true 279 | true 280 | WIN32;INTEL_INTRINSICS;NDEBUG;_WINDOWS;_USRDLL;ADDGRAINC_EXPORTS;%(PreprocessorDefinitions) 281 | true 282 | Sync 283 | MultiThreadedDLL 284 | Default 285 | false 286 | true 287 | StreamingSIMDExtensions 288 | Fast 289 | $(IntDir) 290 | $(IntDir) 291 | $(IntDir) 292 | Level3 293 | true 294 | true 295 | stdcpp17 296 | 297 | 298 | NDEBUG;%(PreprocessorDefinitions) 299 | 0x0409 300 | 301 | 302 | $(IntDir)AddGrainC.dll 303 | true 304 | true 305 | true 306 | MachineX86 307 | true 308 | Console 309 | 310 | 311 | true 312 | 313 | 314 | 315 | 316 | NDEBUG;%(PreprocessorDefinitions) 317 | true 318 | true 319 | Win32 320 | 321 | 322 | 323 | 324 | MaxSpeed 325 | AnySuitable 326 | true 327 | Speed 328 | true 329 | true 330 | WIN32;INTEL_INTRINSICS;NDEBUG;_WINDOWS;_USRDLL;ADDGRAINC_EXPORTS;%(PreprocessorDefinitions) 331 | true 332 | Sync 333 | MultiThreadedDLL 334 | Default 335 | false 336 | true 337 | StreamingSIMDExtensions 338 | Fast 339 | $(IntDir) 340 | $(IntDir) 341 | $(IntDir) 342 | Level3 343 | true 344 | true 345 | stdcpp17 346 | /Zc:threadSafeInit- %(AdditionalOptions) 347 | 348 | 349 | NDEBUG;%(PreprocessorDefinitions) 350 | 0x0409 351 | 352 | 353 | $(IntDir)AddGrainC.dll 354 | true 355 | true 356 | true 357 | MachineX86 358 | true 359 | Console 360 | 361 | 362 | true 363 | 364 | 365 | 366 | 367 | _DEBUG;%(PreprocessorDefinitions) 368 | true 369 | true 370 | X64 371 | 372 | 373 | 374 | Disabled 375 | Default 376 | true 377 | Neither 378 | WIN32;INTEL_INTRINSICS;_DEBUG;_WINDOWS;_USRDLL;ADDGRAINC_EXPORTS;%(PreprocessorDefinitions) 379 | false 380 | Sync 381 | Default 382 | false 383 | MultiThreadedDebug 384 | Default 385 | true 386 | NotSet 387 | 388 | 389 | true 390 | Level3 391 | true 392 | ProgramDatabase 393 | true 394 | stdcpp17 395 | 396 | 397 | _DEBUG;%(PreprocessorDefinitions) 398 | 0x0409 399 | 400 | 401 | true 402 | true 403 | MachineX64 404 | Console 405 | 406 | 407 | true 408 | 409 | 410 | 411 | 412 | NDEBUG;%(PreprocessorDefinitions) 413 | true 414 | true 415 | X64 416 | 417 | 418 | 419 | MaxSpeed 420 | AnySuitable 421 | true 422 | Speed 423 | true 424 | true 425 | WIN32;INTEL_INTRINSICS;NDEBUG;_WINDOWS;_USRDLL;ADDGRAINC_EXPORTS;%(PreprocessorDefinitions) 426 | true 427 | Sync 428 | MultiThreadedDLL 429 | Default 430 | false 431 | true 432 | NotSet 433 | Fast 434 | $(IntDir) 435 | $(IntDir) 436 | $(IntDir) 437 | Level3 438 | true 439 | true 440 | stdcpp17 441 | 442 | 443 | NDEBUG;%(PreprocessorDefinitions) 444 | 0x0409 445 | 446 | 447 | $(IntDir)AddGrainC.dll 448 | true 449 | true 450 | true 451 | MachineX64 452 | true 453 | Console 454 | 455 | 456 | true 457 | 458 | 459 | 460 | 461 | NDEBUG;%(PreprocessorDefinitions) 462 | true 463 | true 464 | X64 465 | 466 | 467 | 468 | 469 | MaxSpeed 470 | AnySuitable 471 | true 472 | Speed 473 | true 474 | true 475 | WIN32;INTEL_INTRINSICS;NDEBUG;_WINDOWS;_USRDLL;ADDGRAINC_EXPORTS;%(PreprocessorDefinitions) 476 | true 477 | Sync 478 | MultiThreadedDLL 479 | Default 480 | false 481 | true 482 | NotSet 483 | Fast 484 | $(IntDir) 485 | $(IntDir) 486 | $(IntDir) 487 | Level3 488 | true 489 | true 490 | stdcpp17 491 | 492 | 493 | NDEBUG;%(PreprocessorDefinitions) 494 | 0x0409 495 | 496 | 497 | $(IntDir)AddGrainC.dll 498 | true 499 | true 500 | true 501 | MachineX64 502 | true 503 | Console 504 | 505 | 506 | true 507 | 508 | 509 | 510 | 511 | NDEBUG;%(PreprocessorDefinitions) 512 | true 513 | true 514 | X64 515 | 516 | 517 | 518 | 519 | MaxSpeed 520 | AnySuitable 521 | true 522 | Speed 523 | true 524 | true 525 | WIN32;INTEL_INTRINSICS;NDEBUG;_WINDOWS;_USRDLL;ADDGRAINC_EXPORTS;%(PreprocessorDefinitions) 526 | true 527 | Sync 528 | MultiThreadedDLL 529 | Default 530 | false 531 | true 532 | NotSet 533 | Fast 534 | $(IntDir) 535 | $(IntDir) 536 | $(IntDir) 537 | Level3 538 | true 539 | true 540 | stdcpp17 541 | /Zc:threadSafeInit- %(AdditionalOptions) 542 | 543 | 544 | NDEBUG;%(PreprocessorDefinitions) 545 | 0x0409 546 | 547 | 548 | $(IntDir)AddGrainC.dll 549 | true 550 | true 551 | true 552 | MachineX64 553 | true 554 | Console 555 | 556 | 557 | true 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | -------------------------------------------------------------------------------- /AddGrainC/avisynth.h: -------------------------------------------------------------------------------- 1 | // Avisynth v2.5. Copyright 2002 Ben Rudiak-Gould et al. 2 | // Avisynth v2.6. Copyright 2006 Klaus Post. 3 | // Avisynth v2.6. Copyright 2009 Ian Brabham. 4 | // Avisynth+ project 5 | // 20160613: new 16 bit planar pixel_type constants go live! 6 | // 20160725: pixel_type constants 10-12-14 bit + planar RGB + BRG48/64 7 | // 20161005: Fallback of VideoInfo functions to defaults if no function exists 8 | // 20170117: global variables for VfW output OPT_xxxx 9 | // 20170310: new MT mode: MT_SPECIAL_MT 10 | // 20171103: (test with SIZETMOD define: Videoframe offsets to size_t, may affect x64) 11 | // 20171207: C++ Standard Conformance (no change for plugin writers) 12 | // 20180525: AVS_UNUSED define to supress parameter not used warnings 13 | // 2020xxxx: AVS_WINDOWS and AVS_POSIX option see avs/config.h 14 | // 20200305: ScriptEnvironment::VSprintf parameter (void *) changed back to va_list 15 | // 20200330: removed __stdcall from variadic argument functions (Sprintf) 16 | // (remove test SIZETMOD define for clarity) 17 | // Integrate Avisynth Neo structures and interface, PFunction, PDevice 18 | // 20200501: frame property support (NewVideoFrameP and other helpers) to legacy IScriptEnvironment. 19 | // move some former IScriptEnvironment2 functions to IScriptEnvironment: 20 | // GetEnvProperty (system prop), Allocate, Free (buffer pool) 21 | // GetVarTry, GetVarBool/Int/String/Double/Long 22 | // Invoke2, Invoke3, InvokeTry, Invoke2Try, Invoke3Try 23 | // Interface Version to 8 (classic 2.6 = 6) 24 | // 20200527 Add IScriptEnvironment_Avs25, used internally 25 | // 20200607 AVS frame property enums to match existing Avisynth enum style 26 | 27 | // http://www.avisynth.org 28 | 29 | // This program is free software; you can redistribute it and/or modify 30 | // it under the terms of the GNU General Public License as published by 31 | // the Free Software Foundation; either version 2 of the License, or 32 | // (at your option) any later version. 33 | // 34 | // This program is distributed in the hope that it will be useful, 35 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | // GNU General Public License for more details. 38 | // 39 | // You should have received a copy of the GNU General Public License 40 | // along with this program; if not, write to the Free Software 41 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 42 | // http://www.gnu.org/copyleft/gpl.html . 43 | // 44 | // Linking Avisynth statically or dynamically with other modules is making 45 | // a combined work based on Avisynth. Thus, the terms and conditions of 46 | // the GNU General Public License cover the whole combination. 47 | // 48 | // As a special exception, the copyright holders of Avisynth give you 49 | // permission to link Avisynth with independent modules that communicate 50 | // with Avisynth solely through the interfaces defined in avisynth.h, 51 | // regardless of the license terms of these independent modules, and to 52 | // copy and distribute the resulting combined work under terms of your 53 | // choice, provided that every copy of the combined work is accompanied 54 | // by a complete copy of the source code of Avisynth (the version of 55 | // Avisynth used to produce the combined work), being distributed under 56 | // the terms of the GNU General Public License plus this exception. An 57 | // independent module is a module which is not derived from or based on 58 | // Avisynth, such as 3rd-party filters, import and export plugins, or 59 | // graphical user interfaces. 60 | 61 | 62 | #ifndef __AVISYNTH_8_H__ 63 | #define __AVISYNTH_8_H__ 64 | 65 | #include "avs/config.h" 66 | #include "avs/capi.h" 67 | #include "avs/types.h" 68 | 69 | #ifdef AVS_POSIX 70 | # include "avs/posix.h" 71 | #endif 72 | 73 | #if defined(AVS_POSIX) 74 | #define __stdcall 75 | #define __cdecl 76 | #endif 77 | 78 | // Important note on AVISYNTH_INTERFACE_VERSION V6->V8 change: 79 | // Note 1: Those few plugins which were using earlier IScriptEnvironment2 despite the big Warning will crash have to be rebuilt. 80 | // Note 2: How to support earlier avisynth interface with an up-to-date avisynth.h: 81 | // Use the new frame property features adaptively after querying that at least v8 is supported 82 | // AviSynth property support can be queried (cpp iface example): 83 | // has_at_least_v8 = true; 84 | // try { env->CheckVersion(8); } catch (const AvisynthError&) { has_at_least_v8 = false; } 85 | // and use it: 86 | // if (has_at_least_v8) dst = env->NewVideoFrameP(vi, &src); else dst = env->NewVideoFrame(vi); 87 | 88 | enum { 89 | AVISYNTH_CLASSIC_INTERFACE_VERSION_25 = 3, 90 | AVISYNTH_CLASSIC_INTERFACE_VERSION_26BETA = 5, 91 | AVISYNTH_CLASSIC_INTERFACE_VERSION = 6, 92 | AVISYNTH_INTERFACE_VERSION = 8 93 | }; 94 | 95 | /* Compiler-specific crap */ 96 | 97 | // Tell MSVC to stop precompiling here 98 | #if defined(_MSC_VER) && !defined(__clang__) 99 | #pragma hdrstop 100 | #endif 101 | 102 | // Set up debugging macros for MS compilers; for others, step down to the 103 | // standard interface 104 | #ifdef _MSC_VER 105 | #include 106 | #else 107 | #undef _RPT0 108 | #undef _RPT1 109 | #undef _RPT2 110 | #undef _RPT3 111 | #undef _RPT4 112 | #undef _RPT5 113 | #define _RPT0(a,b) ((void)0) 114 | #define _RPT1(a,b,c) ((void)0) 115 | #define _RPT2(a,b,c,d) ((void)0) 116 | #define _RPT3(a,b,c,d,e) ((void)0) 117 | #define _RPT4(a,b,c,d,e,f) ((void)0) 118 | #define _RPT5(a,b,c,d,e,f,g) ((void)0) 119 | 120 | #include 121 | #undef _ASSERTE 122 | #undef _ASSERT 123 | #define _ASSERTE(x) assert(x) 124 | #define _ASSERT(x) assert(x) 125 | #endif 126 | 127 | 128 | 129 | // I had problems with Premiere wanting 1-byte alignment for its structures, 130 | // so I now set the Avisynth struct alignment explicitly here. 131 | #pragma pack(push,8) 132 | 133 | // The VideoInfo struct holds global information about a clip (i.e. 134 | // information that does not depend on the frame number). The GetVideoInfo 135 | // method in IClip returns this struct. 136 | 137 | enum {SAMPLE_INT8 = 1<<0, 138 | SAMPLE_INT16 = 1<<1, 139 | SAMPLE_INT24 = 1<<2, // Int24 is a very stupid thing to code, but it's supported by some hardware. 140 | SAMPLE_INT32 = 1<<3, 141 | SAMPLE_FLOAT = 1<<4}; 142 | 143 | enum { 144 | PLANAR_Y=1<<0, 145 | PLANAR_U=1<<1, 146 | PLANAR_V=1<<2, 147 | PLANAR_ALIGNED=1<<3, 148 | PLANAR_Y_ALIGNED=PLANAR_Y|PLANAR_ALIGNED, 149 | PLANAR_U_ALIGNED=PLANAR_U|PLANAR_ALIGNED, 150 | PLANAR_V_ALIGNED=PLANAR_V|PLANAR_ALIGNED, 151 | PLANAR_A=1<<4, 152 | PLANAR_R=1<<5, 153 | PLANAR_G=1<<6, 154 | PLANAR_B=1<<7, 155 | PLANAR_A_ALIGNED=PLANAR_A|PLANAR_ALIGNED, 156 | PLANAR_R_ALIGNED=PLANAR_R|PLANAR_ALIGNED, 157 | PLANAR_G_ALIGNED=PLANAR_G|PLANAR_ALIGNED, 158 | PLANAR_B_ALIGNED=PLANAR_B|PLANAR_ALIGNED, 159 | }; 160 | 161 | class AvisynthError /* exception */ { 162 | public: 163 | const char* const msg; 164 | AvisynthError(const char* _msg) : msg(_msg) {} 165 | 166 | // Ensure AvisynthError cannot be publicly assigned! 167 | private: 168 | AvisynthError& operator=(const AvisynthError&); 169 | }; // end class AvisynthError 170 | 171 | enum AvsDeviceType { 172 | DEV_TYPE_NONE = 0, 173 | DEV_TYPE_CPU = 1, 174 | DEV_TYPE_CUDA = 2, 175 | DEV_TYPE_ANY = 0xFFFF 176 | }; 177 | 178 | /* Forward references */ 179 | #if defined(MSVC) 180 | #define SINGLE_INHERITANCE __single_inheritance 181 | #else 182 | #define SINGLE_INHERITANCE 183 | #endif 184 | struct SINGLE_INHERITANCE VideoInfo; 185 | class SINGLE_INHERITANCE VideoFrameBuffer; 186 | class SINGLE_INHERITANCE VideoFrame; 187 | class IClip; 188 | class SINGLE_INHERITANCE PClip; 189 | class SINGLE_INHERITANCE PVideoFrame; 190 | class IScriptEnvironment; 191 | class SINGLE_INHERITANCE AVSValue; 192 | class INeoEnv; 193 | class IFunction; 194 | class SINGLE_INHERITANCE PFunction; 195 | class Device; 196 | class SINGLE_INHERITANCE PDevice; 197 | class AVSMap; 198 | 199 | 200 | 201 | /* 202 | * Avisynth C++ plugin API code function pointers. 203 | * 204 | * In order to maintain binary compatibility with 205 | * future version do not change the order of the 206 | * existing function pointers. It will be baked 207 | * into all existing plugins. 208 | * 209 | * Add new function pointers to the end of the 210 | * structure. The linkage macros generate some 211 | * protection code to ensure newer plugin do not 212 | * call non-existing functions in an older host. 213 | */ 214 | 215 | struct AVS_Linkage { 216 | 217 | int Size; 218 | 219 | /**********************************************************************/ 220 | 221 | // struct VideoInfo 222 | bool (VideoInfo::*HasVideo)() const; 223 | bool (VideoInfo::*HasAudio)() const; 224 | bool (VideoInfo::*IsRGB)() const; 225 | bool (VideoInfo::*IsRGB24)() const; 226 | bool (VideoInfo::*IsRGB32)() const; 227 | bool (VideoInfo::*IsYUV)() const; 228 | bool (VideoInfo::*IsYUY2)() const; 229 | bool (VideoInfo::*IsYV24)() const; 230 | bool (VideoInfo::*IsYV16)() const; 231 | bool (VideoInfo::*IsYV12)() const; 232 | bool (VideoInfo::*IsYV411)() const; 233 | bool (VideoInfo::*IsY8)() const; 234 | bool (VideoInfo::*IsColorSpace)(int c_space) const; 235 | bool (VideoInfo::*Is)(int property) const; 236 | bool (VideoInfo::*IsPlanar)() const; 237 | bool (VideoInfo::*IsFieldBased)() const; 238 | bool (VideoInfo::*IsParityKnown)() const; 239 | bool (VideoInfo::*IsBFF)() const; 240 | bool (VideoInfo::*IsTFF)() const; 241 | bool (VideoInfo::*IsVPlaneFirst)() const; 242 | int (VideoInfo::*BytesFromPixels)(int pixels) const; 243 | int (VideoInfo::*RowSize)(int plane) const; 244 | int (VideoInfo::*BMPSize)() const; 245 | int64_t (VideoInfo::*AudioSamplesFromFrames)(int frames) const; 246 | int (VideoInfo::*FramesFromAudioSamples)(int64_t samples) const; 247 | int64_t (VideoInfo::*AudioSamplesFromBytes)(int64_t bytes) const; 248 | int64_t (VideoInfo::*BytesFromAudioSamples)(int64_t samples) const; 249 | int (VideoInfo::*AudioChannels)() const; 250 | int (VideoInfo::*SampleType)() const; 251 | bool (VideoInfo::*IsSampleType)(int testtype) const; 252 | int (VideoInfo::*SamplesPerSecond)() const; 253 | int (VideoInfo::*BytesPerAudioSample)() const; 254 | void (VideoInfo::*SetFieldBased)(bool isfieldbased); 255 | void (VideoInfo::*Set)(int property); 256 | void (VideoInfo::*Clear)(int property); 257 | int (VideoInfo::*GetPlaneWidthSubsampling)(int plane) const; 258 | int (VideoInfo::*GetPlaneHeightSubsampling)(int plane) const; 259 | int (VideoInfo::*BitsPerPixel)() const; 260 | int (VideoInfo::*BytesPerChannelSample)() const; 261 | void (VideoInfo::*SetFPS)(unsigned numerator, unsigned denominator); 262 | void (VideoInfo::*MulDivFPS)(unsigned multiplier, unsigned divisor); 263 | bool (VideoInfo::*IsSameColorspace)(const VideoInfo& vi) const; 264 | // end struct VideoInfo 265 | 266 | /**********************************************************************/ 267 | 268 | // class VideoFrameBuffer 269 | const BYTE* (VideoFrameBuffer::*VFBGetReadPtr)() const; 270 | BYTE* (VideoFrameBuffer::*VFBGetWritePtr)(); 271 | int (VideoFrameBuffer::*GetDataSize)() const; 272 | int (VideoFrameBuffer::*GetSequenceNumber)() const; 273 | int (VideoFrameBuffer::*GetRefcount)() const; 274 | // end class VideoFrameBuffer 275 | 276 | /**********************************************************************/ 277 | 278 | // class VideoFrame 279 | int (VideoFrame::*GetPitch)(int plane) const; 280 | int (VideoFrame::*GetRowSize)(int plane) const; 281 | int (VideoFrame::*GetHeight)(int plane) const; 282 | VideoFrameBuffer* (VideoFrame::*GetFrameBuffer)() const; 283 | int (VideoFrame::*GetOffset)(int plane) const; 284 | const BYTE* (VideoFrame::*VFGetReadPtr)(int plane) const; 285 | bool (VideoFrame::*IsWritable)() const; 286 | BYTE* (VideoFrame::*VFGetWritePtr)(int plane) const; 287 | void (VideoFrame::*VideoFrame_DESTRUCTOR)(); 288 | // end class VideoFrame 289 | 290 | /**********************************************************************/ 291 | 292 | // class IClip 293 | /* nothing */ 294 | // end class IClip 295 | 296 | /**********************************************************************/ 297 | 298 | // class PClip 299 | void (PClip::*PClip_CONSTRUCTOR0)(); 300 | void (PClip::*PClip_CONSTRUCTOR1)(const PClip& x); 301 | void (PClip::*PClip_CONSTRUCTOR2)(IClip* x); 302 | void (PClip::*PClip_OPERATOR_ASSIGN0)(IClip* x); 303 | void (PClip::*PClip_OPERATOR_ASSIGN1)(const PClip& x); 304 | void (PClip::*PClip_DESTRUCTOR)(); 305 | // end class PClip 306 | 307 | /**********************************************************************/ 308 | 309 | // class PVideoFrame 310 | void (PVideoFrame::*PVideoFrame_CONSTRUCTOR0)(); 311 | void (PVideoFrame::*PVideoFrame_CONSTRUCTOR1)(const PVideoFrame& x); 312 | void (PVideoFrame::*PVideoFrame_CONSTRUCTOR2)(VideoFrame* x); 313 | void (PVideoFrame::*PVideoFrame_OPERATOR_ASSIGN0)(VideoFrame* x); 314 | void (PVideoFrame::*PVideoFrame_OPERATOR_ASSIGN1)(const PVideoFrame& x); 315 | void (PVideoFrame::*PVideoFrame_DESTRUCTOR)(); 316 | // end class PVideoFrame 317 | 318 | /**********************************************************************/ 319 | 320 | // class AVSValue 321 | void (AVSValue::*AVSValue_CONSTRUCTOR0)(); 322 | void (AVSValue::*AVSValue_CONSTRUCTOR1)(IClip* c); 323 | void (AVSValue::*AVSValue_CONSTRUCTOR2)(const PClip& c); 324 | void (AVSValue::*AVSValue_CONSTRUCTOR3)(bool b); 325 | void (AVSValue::*AVSValue_CONSTRUCTOR4)(int i); 326 | void (AVSValue::*AVSValue_CONSTRUCTOR5)(float f); 327 | void (AVSValue::*AVSValue_CONSTRUCTOR6)(double f); 328 | void (AVSValue::*AVSValue_CONSTRUCTOR7)(const char* s); 329 | void (AVSValue::*AVSValue_CONSTRUCTOR8)(const AVSValue* a, int size); 330 | void (AVSValue::*AVSValue_CONSTRUCTOR9)(const AVSValue& v); 331 | void (AVSValue::*AVSValue_DESTRUCTOR)(); 332 | AVSValue& (AVSValue::*AVSValue_OPERATOR_ASSIGN)(const AVSValue& v); 333 | const AVSValue& (AVSValue::*AVSValue_OPERATOR_INDEX)(int index) const; 334 | bool (AVSValue::*Defined)() const; 335 | bool (AVSValue::*IsClip)() const; 336 | bool (AVSValue::*IsBool)() const; 337 | bool (AVSValue::*IsInt)() const; 338 | bool (AVSValue::*IsFloat)() const; 339 | bool (AVSValue::*IsString)() const; 340 | bool (AVSValue::*IsArray)() const; 341 | PClip (AVSValue::*AsClip)() const; 342 | bool (AVSValue::*AsBool1)() const; 343 | int (AVSValue::*AsInt1)() const; 344 | const char* (AVSValue::*AsString1)() const; 345 | double (AVSValue::*AsFloat1)() const; 346 | bool (AVSValue::*AsBool2)(bool def) const; 347 | int (AVSValue::*AsInt2)(int def) const; 348 | double (AVSValue::*AsDblDef)(double def) const; 349 | double (AVSValue::*AsFloat2)(float def) const; 350 | const char* (AVSValue::*AsString2)(const char* def) const; 351 | int (AVSValue::*ArraySize)() const; 352 | // end class AVSValue 353 | 354 | /**********************************************************************/ 355 | // Reserve pointer space so that we can keep compatibility with Avs "classic" even if it adds functions on its own 356 | void (VideoInfo::*reserved[32])(); 357 | /**********************************************************************/ 358 | // AviSynth+ additions 359 | int (VideoInfo::*NumComponents)() const; 360 | int (VideoInfo::*ComponentSize)() const; 361 | int (VideoInfo::*BitsPerComponent)() const; 362 | bool (VideoInfo::*Is444)() const; 363 | bool (VideoInfo::*Is422)() const; 364 | bool (VideoInfo::*Is420)() const; 365 | bool (VideoInfo::*IsY)() const; 366 | bool (VideoInfo::*IsRGB48)() const; 367 | bool (VideoInfo::*IsRGB64)() const; 368 | bool (VideoInfo::*IsYUVA)() const; 369 | bool (VideoInfo::*IsPlanarRGB)() const; 370 | bool (VideoInfo::*IsPlanarRGBA)() const; 371 | /**********************************************************************/ 372 | 373 | // frame property access 374 | AVSMap& (VideoFrame::* getProperties)(); 375 | const AVSMap& (VideoFrame::* getConstProperties)(); 376 | void (VideoFrame::* setProperties)(const AVSMap& properties); 377 | 378 | // PFunction 379 | void (AVSValue::* AVSValue_CONSTRUCTOR11)(const PFunction& o); 380 | bool (AVSValue::* IsFunction)() const; 381 | void (PFunction::* PFunction_CONSTRUCTOR0)(); 382 | void (PFunction::* PFunction_CONSTRUCTOR1)(IFunction* p); 383 | void (PFunction::* PFunction_CONSTRUCTOR2)(const PFunction& p); 384 | PFunction& (PFunction::* PFunction_OPERATOR_ASSIGN0)(IFunction* other); 385 | PFunction& (PFunction::* PFunction_OPERATOR_ASSIGN1)(const PFunction& other); 386 | void (PFunction::* PFunction_DESTRUCTOR)(); 387 | // end PFunction 388 | 389 | // extra VideoFrame functions 390 | int (VideoFrame::* VideoFrame_CheckMemory)() const; 391 | PDevice (VideoFrame::* VideoFrame_GetDevice)() const; 392 | 393 | // class PDevice, even if only CPU device 394 | void (PDevice::* PDevice_CONSTRUCTOR0)(); 395 | void (PDevice::* PDevice_CONSTRUCTOR1)(Device* p); 396 | void (PDevice::* PDevice_CONSTRUCTOR2)(const PDevice& p); 397 | PDevice& (PDevice::* PDevice_OPERATOR_ASSIGN0)(Device* other); 398 | PDevice& (PDevice::* PDevice_OPERATOR_ASSIGN1)(const PDevice& other); 399 | void (PDevice::* PDevice_DESTRUCTOR)(); 400 | AvsDeviceType (PDevice::* PDevice_GetType)() const; 401 | int (PDevice::* PDevice_GetId)() const; 402 | int (PDevice::* PDevice_GetIndex)() const; 403 | const char* (PDevice::* PDevice_GetName)() const; 404 | // end class PDevice 405 | 406 | /**********************************************************************/ 407 | // Reserve pointer space for Avisynth+ 408 | void (VideoInfo::* reserved2[64 - 23])(); 409 | /**********************************************************************/ 410 | 411 | // AviSynth Neo additions 412 | INeoEnv* (__stdcall *GetNeoEnv)(IScriptEnvironment* env); 413 | // As of V8 most PDevice, PFunction linkage entries are moved to standard avs+ place. 414 | /**********************************************************************/ 415 | 416 | // this part should be identical with AVS_Linkage entries in interface.cpp 417 | }; 418 | 419 | #ifdef BUILDING_AVSCORE 420 | /* Macro resolution for code inside Avisynth.dll */ 421 | # define AVS_BakedCode(arg) ; 422 | # define AVS_LinkCall(arg) 423 | # define AVS_LinkCallV(arg) 424 | # define AVS_LinkCallOpt(arg, argOpt) AVSLinkCall(arg) 425 | # define AVS_LinkCallOptDefault(arg, argDefaultValue) AVSLinkCall(arg()) 426 | # define CALL_MEMBER_FN(object,ptrToMember) 427 | 428 | #else 429 | /* Macro resolution for code inside user plugin */ 430 | # ifdef AVS_LINKAGE_DLLIMPORT 431 | extern __declspec(dllimport) const AVS_Linkage* const AVS_linkage; 432 | # else 433 | extern const AVS_Linkage* AVS_linkage; 434 | # endif 435 | 436 | # ifndef offsetof 437 | # include 438 | # endif 439 | 440 | # define AVS_BakedCode(arg) { arg ; } 441 | # define AVS_LinkCall(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? 0 : (this->*(AVS_linkage->arg)) 442 | # define AVS_LinkCall_Void(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? (void)0 : (this->*(AVS_linkage->arg)) 443 | # define AVS_LinkCallV(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? *this : (this->*(AVS_linkage->arg)) 444 | // Helper macros for fallback option when a function does not exists 445 | #define CALL_MEMBER_FN(object,ptrToMember) ((object)->*(ptrToMember)) 446 | #define AVS_LinkCallOpt(arg, argOpt) !AVS_linkage ? 0 : \ 447 | ( offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? \ 448 | (offsetof(AVS_Linkage, argOpt) >= AVS_linkage->Size ? 0 : CALL_MEMBER_FN(this, AVS_linkage->argOpt)() ) : \ 449 | CALL_MEMBER_FN(this, AVS_linkage->arg)() ) 450 | // AVS_LinkCallOptDefault puts automatically () only after arg 451 | # define AVS_LinkCallOptDefault(arg, argDefaultValue) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? (argDefaultValue) : ((this->*(AVS_linkage->arg))()) 452 | 453 | #endif 454 | 455 | class PDevice 456 | { 457 | public: 458 | PDevice() AVS_BakedCode(AVS_LinkCall_Void(PDevice_CONSTRUCTOR0)()) 459 | PDevice(Device* p) AVS_BakedCode(AVS_LinkCall_Void(PDevice_CONSTRUCTOR1)(p)) 460 | PDevice(const PDevice& p) AVS_BakedCode(AVS_LinkCall_Void(PDevice_CONSTRUCTOR2)(p)) 461 | PDevice& operator=(Device* p) AVS_BakedCode(return AVS_LinkCallV(PDevice_OPERATOR_ASSIGN0)(p)) 462 | PDevice& operator=(const PDevice& p) AVS_BakedCode(return AVS_LinkCallV(PDevice_OPERATOR_ASSIGN1)(p)) 463 | ~PDevice() AVS_BakedCode(AVS_LinkCall_Void(PDevice_DESTRUCTOR)()) 464 | 465 | int operator!() const { return !e; } 466 | operator void*() const { return e; } 467 | Device* operator->() const { return e; } 468 | 469 | AvsDeviceType GetType() const AVS_BakedCode(return AVS_LinkCallOptDefault(PDevice_GetType, DEV_TYPE_NONE)) 470 | int GetId() const AVS_BakedCode(return AVS_LinkCall(PDevice_GetId)()) 471 | int GetIndex() const AVS_BakedCode(return AVS_LinkCall(PDevice_GetIndex)()) 472 | const char* GetName() const AVS_BakedCode(return AVS_LinkCall(PDevice_GetName)()) 473 | 474 | private: 475 | Device * e; 476 | 477 | #ifdef BUILDING_AVSCORE 478 | public: 479 | void CONSTRUCTOR0(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 480 | void CONSTRUCTOR1(Device* p); 481 | void CONSTRUCTOR2(const PDevice& p); 482 | PDevice& OPERATOR_ASSIGN0(Device* p); 483 | PDevice& OPERATOR_ASSIGN1(const PDevice& p); 484 | void DESTRUCTOR(); 485 | #endif 486 | }; 487 | struct VideoInfo { 488 | int width, height; // width=0 means no video 489 | unsigned fps_numerator, fps_denominator; 490 | int num_frames; 491 | // This is more extensible than previous versions. More properties can be added seeminglesly. 492 | 493 | // Colorspace properties. 494 | /* 495 | 496 | Planar match mask 1111.1000.0000.0111.0000.0111.0000.0111 497 | Planar signature 10xx.1000.0000.00xx.0000.00xx.00xx.00xx ? 498 | Planar signature 10xx.1000.0000.0xxx.0000.00xx.000x.x0xx ? *new 499 | Planar filter mask 1111.1111.1111.1111.1111.1111.1110.0111 (typo from old header fixed) 500 | 501 | pixel_type mapping 502 | ================== 503 | pixel_type bit-map PIYB.Z000.0???.0SSS.0000.0???.????.???? 504 | planar YUV CCC HHH.000u.vWWW 505 | planar RGB(A) CCC AR 506 | nonplanar CCC 000.00wx xyAR 507 | Legend 508 | ====== 509 | Planar YUV: 510 | Code Bits Remark 511 | W 0-2 Planar Width Subsampling bits 512 | Use (X+1) & 3 for GetPlaneWidthSubsampling 513 | 000 => 1 YV12, YV16, YUV420, YUV422 514 | 001 => 2 YV411, YUV9 515 | 010 => reserved 516 | 011 => 0 YV24, YUV444, RGBP 517 | 1xx => reserved 518 | v 3 VPlaneFirst YV12, YV16, YV24, YV411, YUV9 519 | u 4 UPlaneFirst I420 520 | H 7-9 Planar Height Subsampling bits 521 | Use ((X>>8)+1) & 3 for GetPlaneHeightSubsampling 522 | 000 => 1 YV12, YUV420 523 | 001 => 2 YUV9 524 | 010 => reserved 525 | 011 => 0 YV16, YV24, YV411, YUV422, YUV444, RGBP 526 | 1xx => reserved 527 | 528 | Planar RGB 529 | Code Bits Remark 530 | R 0 BGR, (with SSS bits for 8/16 bit/sample or float) 531 | A 1 BGRA, (with SSS bits for 8/16 bit/sample or float) 532 | 533 | 534 | Not Planar, Interleaved (I flag) 535 | Code Bits Remark 536 | R 0 BGR24, and BGRx in future (with SSS bits for 8/16 bit/sample or float) 537 | A 1 BGR32, and BGRAx in future (with SSS bits for 8/16 bit/sample or float) 538 | y 2 YUY2 539 | x 3-4 reserved 540 | w 5 Raw32 541 | 542 | General 543 | Code Bits Remark 544 | S 16-18 Sample resolution bits 545 | 000 => 8 546 | 001 => 16 547 | 010 => 32 (float) 548 | 011,100 => reserved 549 | 101 => 10 bits 550 | 110 => 12 bits 551 | 111 => 14 bits 552 | for packed RGB(A): only 8 and 16 bits are valid 553 | 554 | Other YV12 specific (not used?) 555 | C 20-22 Chroma Placement values 0-4 see CS_xxx_CHROMA_PLACEMENT 556 | 557 | Color family and layout 558 | Packed Planar Planar Planar 559 | Code Bits Remark RGB/RGBA YUV YUY2 Y_Grey RGB/RGBA YUVA 560 | R 0 1/0 - 0 - 1/0 - 561 | A 1 0/1 - 0 - 0/1 - 562 | y 2 - - 1 - 0 - 563 | Z 27 YUVA 0 0 0 0 1 1 564 | B 28 BGR 1 0 0 0 1* 0 565 | Y 29 YUV 0 1 1 1 0 0 566 | I 30 Interleaved 1 0 1 1 0 0 567 | P 31 Planar 0 1 0 1 1 1 568 | * Planar RGB plane order: G,B,R(,A) 569 | 570 | */ 571 | enum { 572 | CS_YUVA = 1<<27, 573 | CS_BGR = 1<<28, 574 | CS_YUV = 1<<29, 575 | CS_INTERLEAVED = 1<<30, 576 | CS_PLANAR = 1<<31, 577 | 578 | CS_Shift_Sub_Width = 0, 579 | CS_Shift_Sub_Height = 8, 580 | CS_Shift_Sample_Bits = 16, 581 | 582 | CS_Sub_Width_Mask = 7 << CS_Shift_Sub_Width, 583 | CS_Sub_Width_1 = 3 << CS_Shift_Sub_Width, // YV24 584 | CS_Sub_Width_2 = 0 << CS_Shift_Sub_Width, // YV12, I420, YV16 585 | CS_Sub_Width_4 = 1 << CS_Shift_Sub_Width, // YUV9, YV411 586 | 587 | CS_VPlaneFirst = 1 << 3, // YV12, YV16, YV24, YV411, YUV9 588 | CS_UPlaneFirst = 1 << 4, // I420 589 | 590 | CS_Sub_Height_Mask = 7 << CS_Shift_Sub_Height, 591 | CS_Sub_Height_1 = 3 << CS_Shift_Sub_Height, // YV16, YV24, YV411 592 | CS_Sub_Height_2 = 0 << CS_Shift_Sub_Height, // YV12, I420 593 | CS_Sub_Height_4 = 1 << CS_Shift_Sub_Height, // YUV9 594 | 595 | CS_Sample_Bits_Mask = 7 << CS_Shift_Sample_Bits, 596 | CS_Sample_Bits_8 = 0 << CS_Shift_Sample_Bits, 597 | CS_Sample_Bits_10 = 5 << CS_Shift_Sample_Bits, 598 | CS_Sample_Bits_12 = 6 << CS_Shift_Sample_Bits, 599 | CS_Sample_Bits_14 = 7 << CS_Shift_Sample_Bits, 600 | CS_Sample_Bits_16 = 1 << CS_Shift_Sample_Bits, 601 | CS_Sample_Bits_32 = 2 << CS_Shift_Sample_Bits, 602 | 603 | CS_PLANAR_MASK = CS_PLANAR | CS_INTERLEAVED | CS_YUV | CS_BGR | CS_YUVA | CS_Sample_Bits_Mask 604 | | CS_Sub_Height_Mask | CS_Sub_Width_Mask, 605 | CS_PLANAR_FILTER = ~( CS_VPlaneFirst | CS_UPlaneFirst ), 606 | 607 | CS_RGB_TYPE = 1 << 0, 608 | CS_RGBA_TYPE = 1 << 1, 609 | 610 | // Specific colorformats 611 | CS_UNKNOWN = 0, 612 | 613 | CS_BGR24 = CS_RGB_TYPE | CS_BGR | CS_INTERLEAVED, 614 | CS_BGR32 = CS_RGBA_TYPE | CS_BGR | CS_INTERLEAVED, 615 | CS_YUY2 = 1<<2 | CS_YUV | CS_INTERLEAVED, 616 | // CS_YV12 = 1<<3 Reserved 617 | // CS_I420 = 1<<4 Reserved 618 | CS_RAW32 = 1<<5 | CS_INTERLEAVED, 619 | 620 | // YV12 must be 0xA000008 2.5 Baked API will see all new planar as YV12 621 | // I420 must be 0xA000010 622 | 623 | CS_GENERIC_YUV420 = CS_PLANAR | CS_YUV | CS_VPlaneFirst | CS_Sub_Height_2 | CS_Sub_Width_2, // 4:2:0 planar 624 | CS_GENERIC_YUV422 = CS_PLANAR | CS_YUV | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_2, // 4:2:2 planar 625 | CS_GENERIC_YUV444 = CS_PLANAR | CS_YUV | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_1, // 4:4:4 planar 626 | CS_GENERIC_Y = CS_PLANAR | CS_INTERLEAVED | CS_YUV, // Y only (4:0:0) 627 | CS_GENERIC_RGBP = CS_PLANAR | CS_BGR | CS_RGB_TYPE, // planar RGB. Though name is RGB but plane order G,B,R 628 | CS_GENERIC_RGBAP = CS_PLANAR | CS_BGR | CS_RGBA_TYPE, // planar RGBA 629 | CS_GENERIC_YUVA420 = CS_PLANAR | CS_YUVA | CS_VPlaneFirst | CS_Sub_Height_2 | CS_Sub_Width_2, // 4:2:0:A planar 630 | CS_GENERIC_YUVA422 = CS_PLANAR | CS_YUVA | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_2, // 4:2:2:A planar 631 | CS_GENERIC_YUVA444 = CS_PLANAR | CS_YUVA | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_1, // 4:4:4:A planar 632 | 633 | CS_YV24 = CS_GENERIC_YUV444 | CS_Sample_Bits_8, // YVU 4:4:4 planar 634 | CS_YV16 = CS_GENERIC_YUV422 | CS_Sample_Bits_8, // YVU 4:2:2 planar 635 | CS_YV12 = CS_GENERIC_YUV420 | CS_Sample_Bits_8, // YVU 4:2:0 planar 636 | CS_I420 = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_UPlaneFirst | CS_Sub_Height_2 | CS_Sub_Width_2, // YUV 4:2:0 planar 637 | CS_IYUV = CS_I420, 638 | CS_YUV9 = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_4 | CS_Sub_Width_4, // YUV 4:1:0 planar 639 | CS_YV411 = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_4, // YUV 4:1:1 planar 640 | 641 | CS_Y8 = CS_GENERIC_Y | CS_Sample_Bits_8, // Y 4:0:0 planar 642 | 643 | //------------------------- 644 | // AVS16: new planar constants go live! Experimental PF 160613 645 | // 10-12-14 bit + planar RGB + BRG48/64 160725 646 | 647 | CS_YUV444P10 = CS_GENERIC_YUV444 | CS_Sample_Bits_10, // YUV 4:4:4 10bit samples 648 | CS_YUV422P10 = CS_GENERIC_YUV422 | CS_Sample_Bits_10, // YUV 4:2:2 10bit samples 649 | CS_YUV420P10 = CS_GENERIC_YUV420 | CS_Sample_Bits_10, // YUV 4:2:0 10bit samples 650 | CS_Y10 = CS_GENERIC_Y | CS_Sample_Bits_10, // Y 4:0:0 10bit samples 651 | 652 | CS_YUV444P12 = CS_GENERIC_YUV444 | CS_Sample_Bits_12, // YUV 4:4:4 12bit samples 653 | CS_YUV422P12 = CS_GENERIC_YUV422 | CS_Sample_Bits_12, // YUV 4:2:2 12bit samples 654 | CS_YUV420P12 = CS_GENERIC_YUV420 | CS_Sample_Bits_12, // YUV 4:2:0 12bit samples 655 | CS_Y12 = CS_GENERIC_Y | CS_Sample_Bits_12, // Y 4:0:0 12bit samples 656 | 657 | CS_YUV444P14 = CS_GENERIC_YUV444 | CS_Sample_Bits_14, // YUV 4:4:4 14bit samples 658 | CS_YUV422P14 = CS_GENERIC_YUV422 | CS_Sample_Bits_14, // YUV 4:2:2 14bit samples 659 | CS_YUV420P14 = CS_GENERIC_YUV420 | CS_Sample_Bits_14, // YUV 4:2:0 14bit samples 660 | CS_Y14 = CS_GENERIC_Y | CS_Sample_Bits_14, // Y 4:0:0 14bit samples 661 | 662 | CS_YUV444P16 = CS_GENERIC_YUV444 | CS_Sample_Bits_16, // YUV 4:4:4 16bit samples 663 | CS_YUV422P16 = CS_GENERIC_YUV422 | CS_Sample_Bits_16, // YUV 4:2:2 16bit samples 664 | CS_YUV420P16 = CS_GENERIC_YUV420 | CS_Sample_Bits_16, // YUV 4:2:0 16bit samples 665 | CS_Y16 = CS_GENERIC_Y | CS_Sample_Bits_16, // Y 4:0:0 16bit samples 666 | 667 | // 32 bit samples (float) 668 | CS_YUV444PS = CS_GENERIC_YUV444 | CS_Sample_Bits_32, // YUV 4:4:4 32bit samples 669 | CS_YUV422PS = CS_GENERIC_YUV422 | CS_Sample_Bits_32, // YUV 4:2:2 32bit samples 670 | CS_YUV420PS = CS_GENERIC_YUV420 | CS_Sample_Bits_32, // YUV 4:2:0 32bit samples 671 | CS_Y32 = CS_GENERIC_Y | CS_Sample_Bits_32, // Y 4:0:0 32bit samples 672 | 673 | // RGB packed 674 | CS_BGR48 = CS_RGB_TYPE | CS_BGR | CS_INTERLEAVED | CS_Sample_Bits_16, // BGR 3x16 bit 675 | CS_BGR64 = CS_RGBA_TYPE | CS_BGR | CS_INTERLEAVED | CS_Sample_Bits_16, // BGR 4x16 bit 676 | // no packed 32 bit (float) support for these legacy types 677 | 678 | // RGB planar 679 | CS_RGBP = CS_GENERIC_RGBP | CS_Sample_Bits_8, // Planar RGB 8 bit samples 680 | CS_RGBP8 = CS_GENERIC_RGBP | CS_Sample_Bits_8, // Planar RGB 8 bit samples 681 | CS_RGBP10 = CS_GENERIC_RGBP | CS_Sample_Bits_10, // Planar RGB 10bit samples 682 | CS_RGBP12 = CS_GENERIC_RGBP | CS_Sample_Bits_12, // Planar RGB 12bit samples 683 | CS_RGBP14 = CS_GENERIC_RGBP | CS_Sample_Bits_14, // Planar RGB 14bit samples 684 | CS_RGBP16 = CS_GENERIC_RGBP | CS_Sample_Bits_16, // Planar RGB 16bit samples 685 | CS_RGBPS = CS_GENERIC_RGBP | CS_Sample_Bits_32, // Planar RGB 32bit samples 686 | 687 | // RGBA planar 688 | CS_RGBAP = CS_GENERIC_RGBAP | CS_Sample_Bits_8, // Planar RGBA 8 bit samples 689 | CS_RGBAP8 = CS_GENERIC_RGBAP | CS_Sample_Bits_8, // Planar RGBA 8 bit samples 690 | CS_RGBAP10 = CS_GENERIC_RGBAP | CS_Sample_Bits_10, // Planar RGBA 10bit samples 691 | CS_RGBAP12 = CS_GENERIC_RGBAP | CS_Sample_Bits_12, // Planar RGBA 12bit samples 692 | CS_RGBAP14 = CS_GENERIC_RGBAP | CS_Sample_Bits_14, // Planar RGBA 14bit samples 693 | CS_RGBAP16 = CS_GENERIC_RGBAP | CS_Sample_Bits_16, // Planar RGBA 16bit samples 694 | CS_RGBAPS = CS_GENERIC_RGBAP | CS_Sample_Bits_32, // Planar RGBA 32bit samples 695 | 696 | // Planar YUVA 697 | CS_YUVA444 = CS_GENERIC_YUVA444 | CS_Sample_Bits_8, // YUVA 4:4:4 8bit samples 698 | CS_YUVA422 = CS_GENERIC_YUVA422 | CS_Sample_Bits_8, // YUVA 4:2:2 8bit samples 699 | CS_YUVA420 = CS_GENERIC_YUVA420 | CS_Sample_Bits_8, // YUVA 4:2:0 8bit samples 700 | 701 | CS_YUVA444P10 = CS_GENERIC_YUVA444 | CS_Sample_Bits_10, // YUVA 4:4:4 10bit samples 702 | CS_YUVA422P10 = CS_GENERIC_YUVA422 | CS_Sample_Bits_10, // YUVA 4:2:2 10bit samples 703 | CS_YUVA420P10 = CS_GENERIC_YUVA420 | CS_Sample_Bits_10, // YUVA 4:2:0 10bit samples 704 | 705 | CS_YUVA444P12 = CS_GENERIC_YUVA444 | CS_Sample_Bits_12, // YUVA 4:4:4 12bit samples 706 | CS_YUVA422P12 = CS_GENERIC_YUVA422 | CS_Sample_Bits_12, // YUVA 4:2:2 12bit samples 707 | CS_YUVA420P12 = CS_GENERIC_YUVA420 | CS_Sample_Bits_12, // YUVA 4:2:0 12bit samples 708 | 709 | CS_YUVA444P14 = CS_GENERIC_YUVA444 | CS_Sample_Bits_14, // YUVA 4:4:4 14bit samples 710 | CS_YUVA422P14 = CS_GENERIC_YUVA422 | CS_Sample_Bits_14, // YUVA 4:2:2 14bit samples 711 | CS_YUVA420P14 = CS_GENERIC_YUVA420 | CS_Sample_Bits_14, // YUVA 4:2:0 14bit samples 712 | 713 | CS_YUVA444P16 = CS_GENERIC_YUVA444 | CS_Sample_Bits_16, // YUVA 4:4:4 16bit samples 714 | CS_YUVA422P16 = CS_GENERIC_YUVA422 | CS_Sample_Bits_16, // YUVA 4:2:2 16bit samples 715 | CS_YUVA420P16 = CS_GENERIC_YUVA420 | CS_Sample_Bits_16, // YUVA 4:2:0 16bit samples 716 | 717 | CS_YUVA444PS = CS_GENERIC_YUVA444 | CS_Sample_Bits_32, // YUVA 4:4:4 32bit samples 718 | CS_YUVA422PS = CS_GENERIC_YUVA422 | CS_Sample_Bits_32, // YUVA 4:2:2 32bit samples 719 | CS_YUVA420PS = CS_GENERIC_YUVA420 | CS_Sample_Bits_32, // YUVA 4:2:0 32bit samples 720 | 721 | }; 722 | 723 | int pixel_type; // changed to int as of 2.5 724 | 725 | 726 | int audio_samples_per_second; // 0 means no audio 727 | int sample_type; // as of 2.5 728 | int64_t num_audio_samples; // changed as of 2.5 729 | int nchannels; // as of 2.5 730 | 731 | // Imagetype properties 732 | 733 | int image_type; 734 | 735 | enum { 736 | IT_BFF = 1<<0, 737 | IT_TFF = 1<<1, 738 | IT_FIELDBASED = 1<<2 739 | }; 740 | 741 | // Chroma placement bits 20 -> 23 ::FIXME:: Really want a Class to support this 742 | enum { 743 | CS_UNKNOWN_CHROMA_PLACEMENT = 0 << 20, 744 | CS_MPEG1_CHROMA_PLACEMENT = 1 << 20, 745 | CS_MPEG2_CHROMA_PLACEMENT = 2 << 20, 746 | CS_YUY2_CHROMA_PLACEMENT = 3 << 20, 747 | CS_TOPLEFT_CHROMA_PLACEMENT = 4 << 20 748 | }; 749 | 750 | // useful functions of the above 751 | bool HasVideo() const AVS_BakedCode(return AVS_LinkCall(HasVideo)()) 752 | bool HasAudio() const AVS_BakedCode(return AVS_LinkCall(HasAudio)()) 753 | bool IsRGB() const AVS_BakedCode(return AVS_LinkCall(IsRGB)()) 754 | bool IsRGB24() const AVS_BakedCode(return AVS_LinkCall(IsRGB24)()) 755 | bool IsRGB32() const AVS_BakedCode(return AVS_LinkCall(IsRGB32)()) 756 | bool IsYUV() const AVS_BakedCode(return AVS_LinkCall(IsYUV)()) 757 | bool IsYUY2() const AVS_BakedCode(return AVS_LinkCall(IsYUY2)()) 758 | 759 | bool IsYV24() const AVS_BakedCode(return AVS_LinkCall(IsYV24)()) 760 | bool IsYV16() const AVS_BakedCode(return AVS_LinkCall(IsYV16)()) 761 | bool IsYV12() const AVS_BakedCode(return AVS_LinkCall(IsYV12)()) 762 | bool IsYV411() const AVS_BakedCode(return AVS_LinkCall(IsYV411)()) 763 | //bool IsYUV9() const; 764 | bool IsY8() const AVS_BakedCode(return AVS_LinkCall(IsY8)()) 765 | 766 | bool IsColorSpace(int c_space) const AVS_BakedCode(return AVS_LinkCall(IsColorSpace)(c_space)) 767 | 768 | bool Is(int property) const AVS_BakedCode(return AVS_LinkCall(Is)(property)) 769 | bool IsPlanar() const AVS_BakedCode(return AVS_LinkCall(IsPlanar)()) 770 | bool IsFieldBased() const AVS_BakedCode(return AVS_LinkCall(IsFieldBased)()) 771 | bool IsParityKnown() const AVS_BakedCode(return AVS_LinkCall(IsParityKnown)()) 772 | bool IsBFF() const AVS_BakedCode(return AVS_LinkCall(IsBFF)()) 773 | bool IsTFF() const AVS_BakedCode(return AVS_LinkCall(IsTFF)()) 774 | 775 | bool IsVPlaneFirst() const AVS_BakedCode(return AVS_LinkCall(IsVPlaneFirst)()) // Don't use this 776 | // Will not work on planar images, but will return only luma planes 777 | int BytesFromPixels(int pixels) const AVS_BakedCode(return AVS_LinkCall(BytesFromPixels)(pixels)) 778 | int RowSize(int plane = 0) const AVS_BakedCode(return AVS_LinkCall(RowSize)(plane)) 779 | int BMPSize() const AVS_BakedCode(return AVS_LinkCall(BMPSize)()) 780 | 781 | int64_t AudioSamplesFromFrames(int frames) const AVS_BakedCode(return AVS_LinkCall(AudioSamplesFromFrames)(frames)) 782 | int FramesFromAudioSamples(int64_t samples) const AVS_BakedCode(return AVS_LinkCall(FramesFromAudioSamples)(samples)) 783 | int64_t AudioSamplesFromBytes(int64_t bytes) const AVS_BakedCode(return AVS_LinkCall(AudioSamplesFromBytes)(bytes)) 784 | int64_t BytesFromAudioSamples(int64_t samples) const AVS_BakedCode(return AVS_LinkCall(BytesFromAudioSamples)(samples)) 785 | int AudioChannels() const AVS_BakedCode(return AVS_LinkCall(AudioChannels)()) 786 | int SampleType() const AVS_BakedCode(return AVS_LinkCall(SampleType)()) 787 | bool IsSampleType(int testtype) const AVS_BakedCode(return AVS_LinkCall(IsSampleType)(testtype)) 788 | int SamplesPerSecond() const AVS_BakedCode(return AVS_LinkCall(SamplesPerSecond)()) 789 | int BytesPerAudioSample() const AVS_BakedCode(return AVS_LinkCall(BytesPerAudioSample)()) 790 | void SetFieldBased(bool isfieldbased) AVS_BakedCode(AVS_LinkCall_Void(SetFieldBased)(isfieldbased)) 791 | void Set(int property) AVS_BakedCode(AVS_LinkCall_Void(Set)(property)) 792 | void Clear(int property) AVS_BakedCode(AVS_LinkCall_Void(Clear)(property)) 793 | // Subsampling in bitshifts! 794 | int GetPlaneWidthSubsampling(int plane) const AVS_BakedCode(return AVS_LinkCall(GetPlaneWidthSubsampling)(plane)) 795 | int GetPlaneHeightSubsampling(int plane) const AVS_BakedCode(return AVS_LinkCall(GetPlaneHeightSubsampling)(plane)) 796 | int BitsPerPixel() const AVS_BakedCode(return AVS_LinkCall(BitsPerPixel)()) 797 | 798 | int BytesPerChannelSample() const AVS_BakedCode(return AVS_LinkCall(BytesPerChannelSample)()) 799 | 800 | // useful mutator 801 | void SetFPS(unsigned numerator, unsigned denominator) AVS_BakedCode(AVS_LinkCall_Void(SetFPS)(numerator, denominator)) 802 | 803 | // Range protected multiply-divide of FPS 804 | void MulDivFPS(unsigned multiplier, unsigned divisor) AVS_BakedCode(AVS_LinkCall_Void(MulDivFPS)(multiplier, divisor)) 805 | 806 | // Test for same colorspace 807 | bool IsSameColorspace(const VideoInfo& vi) const AVS_BakedCode(return AVS_LinkCall(IsSameColorspace)(vi)) 808 | 809 | // AVS+ extensions 810 | // 20161005: 811 | // Mapping of AVS+ extensions to classic 2.6 functions. 812 | // In order to use these extended AVS+ functions for plugins that should work 813 | // either with AVS+ or with Classic (8 bit) Avs 2.6 ans earlier AVS+ versions, there is an 814 | // automatic fallback mechanism. 815 | // From AVS+'s point of view these are not "baked" codes, the primary functions should exist. 816 | // Examples: 817 | // Is444() is mapped to IsYV24() for classic AVS2.6 818 | // ComponentSize() returns constant 1 (1 bytes per pixel component) 819 | // BitsPerComponent() returns constant 8 (Classic AVS2.6 is 8 bit only) 820 | 821 | // Returns the number of color channels or planes in a frame 822 | int NumComponents() const AVS_BakedCode(return AVS_LinkCallOptDefault(NumComponents, (((AVS_LinkCall(IsYUV)()) && !(AVS_LinkCall(IsY8)())) ? 3 : AVS_LinkCall(BytesFromPixels)(1)) ) ) 823 | 824 | // Returns the size in bytes of a single component of a pixel 825 | int ComponentSize() const AVS_BakedCode(return AVS_LinkCallOptDefault(ComponentSize, 1)) 826 | 827 | // Returns the bit depth of a single component of a pixel 828 | int BitsPerComponent() const AVS_BakedCode(return AVS_LinkCallOptDefault(BitsPerComponent, 8)) 829 | 830 | // like IsYV24, but bit-depth independent also for YUVA 831 | bool Is444() const AVS_BakedCode(return AVS_LinkCallOpt(Is444, IsYV24) ) 832 | 833 | // like IsYV16, but bit-depth independent also for YUVA 834 | bool Is422() const AVS_BakedCode(return AVS_LinkCallOpt(Is422, IsYV16) ) 835 | 836 | // like IsYV12, but bit-depth independent also for YUVA 837 | bool Is420() const AVS_BakedCode( return AVS_LinkCallOpt(Is420, IsYV12) ) 838 | 839 | // like IsY8, but bit-depth independent 840 | bool IsY() const AVS_BakedCode( return AVS_LinkCallOpt(IsY, IsY8) ) 841 | 842 | // like IsRGB24 for 16 bit samples 843 | bool IsRGB48() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsRGB48, false) ) 844 | 845 | // like IsRGB32 for 16 bit samples 846 | bool IsRGB64() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsRGB64, false) ) 847 | 848 | // YUVA? 849 | bool IsYUVA() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsYUVA, false) ) 850 | 851 | // Planar RGB? 852 | bool IsPlanarRGB() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsPlanarRGB, false) ) 853 | 854 | // Planar RGBA? 855 | bool IsPlanarRGBA() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsPlanarRGBA, false) ) 856 | 857 | }; // end struct VideoInfo 858 | 859 | 860 | 861 | 862 | // VideoFrameBuffer holds information about a memory block which is used 863 | // for video data. For efficiency, instances of this class are not deleted 864 | // when the refcount reaches zero; instead they're stored in a linked list 865 | // to be reused. The instances are deleted when the corresponding AVS 866 | // file is closed. 867 | 868 | class VideoFrameBuffer { 869 | BYTE* data; 870 | int data_size; 871 | // sequence_number is incremented every time the buffer is changed, so 872 | // that stale views can tell they're no longer valid. 873 | volatile long sequence_number; 874 | 875 | friend class VideoFrame; 876 | friend class Cache; 877 | friend class ScriptEnvironment; 878 | volatile long refcount; 879 | 880 | // AVS+CUDA extension, does not break plugins if appended here 881 | Device* device; 882 | 883 | protected: 884 | VideoFrameBuffer(int size, int margin, Device* device); 885 | VideoFrameBuffer(); 886 | ~VideoFrameBuffer(); 887 | 888 | public: 889 | const BYTE* GetReadPtr() const AVS_BakedCode( return AVS_LinkCall(VFBGetReadPtr)() ) 890 | BYTE* GetWritePtr() AVS_BakedCode( return AVS_LinkCall(VFBGetWritePtr)() ) 891 | int GetDataSize() const AVS_BakedCode( return AVS_LinkCall(GetDataSize)() ) 892 | int GetSequenceNumber() const AVS_BakedCode( return AVS_LinkCall(GetSequenceNumber)() ) 893 | int GetRefcount() const AVS_BakedCode( return AVS_LinkCall(GetRefcount)() ) 894 | 895 | // Ensure VideoFrameBuffer cannot be publicly assigned 896 | private: 897 | VideoFrameBuffer& operator=(const VideoFrameBuffer&); 898 | 899 | }; // end class VideoFrameBuffer 900 | 901 | 902 | // smart pointer to VideoFrame 903 | class PVideoFrame { 904 | 905 | VideoFrame* p; 906 | 907 | void Init(VideoFrame* x); 908 | void Set(VideoFrame* x); 909 | 910 | public: 911 | PVideoFrame() AVS_BakedCode(AVS_LinkCall_Void(PVideoFrame_CONSTRUCTOR0)()) 912 | PVideoFrame(const PVideoFrame& x) AVS_BakedCode(AVS_LinkCall_Void(PVideoFrame_CONSTRUCTOR1)(x)) 913 | PVideoFrame(VideoFrame* x) AVS_BakedCode(AVS_LinkCall_Void(PVideoFrame_CONSTRUCTOR2)(x)) 914 | void operator=(VideoFrame* x) AVS_BakedCode(AVS_LinkCall_Void(PVideoFrame_OPERATOR_ASSIGN0)(x)) 915 | void operator=(const PVideoFrame& x) AVS_BakedCode(AVS_LinkCall_Void(PVideoFrame_OPERATOR_ASSIGN1)(x)) 916 | 917 | VideoFrame* operator->() const { return p; } 918 | 919 | // for conditional expressions 920 | operator void*() const { return p; } 921 | bool operator!() const { return !p; } 922 | 923 | ~PVideoFrame() AVS_BakedCode(AVS_LinkCall_Void(PVideoFrame_DESTRUCTOR)()) 924 | #ifdef BUILDING_AVSCORE 925 | public: 926 | void CONSTRUCTOR0(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 927 | void CONSTRUCTOR1(const PVideoFrame& x); 928 | void CONSTRUCTOR2(VideoFrame* x); 929 | void OPERATOR_ASSIGN0(VideoFrame* x); 930 | void OPERATOR_ASSIGN1(const PVideoFrame& x); 931 | void DESTRUCTOR(); 932 | #endif 933 | }; // end class PVideoFrame 934 | 935 | 936 | // VideoFrame holds a "window" into a VideoFrameBuffer. Operator new 937 | // is overloaded to recycle class instances. 938 | 939 | class VideoFrame { 940 | volatile long refcount; 941 | VideoFrameBuffer* vfb; 942 | 943 | // Due to technical reasons these members are not const, but should be treated as such. 944 | // That means do not modify them once the class has been constructed. 945 | int offset; 946 | int pitch, row_size, height; 947 | int offsetU, offsetV; // U&V offsets are from top of picture. 948 | int pitchUV, row_sizeUV, heightUV; // for Planar RGB offsetU, offsetV is for the 2nd and 3rd Plane. 949 | // for Planar RGB pitchUV and row_sizeUV = 0, because when no VideoInfo (MakeWriteable) 950 | // the decision on existance of UV is checked by zero pitch 951 | // AVS+ extension, does not break plugins if appended here 952 | int offsetA; 953 | int pitchA, row_sizeA; // 4th alpha plane support, pitch and row_size is 0 is none 954 | 955 | AVSMap *properties; 956 | 957 | friend class PVideoFrame; 958 | void AddRef(); 959 | void Release(); 960 | 961 | friend class ScriptEnvironment; 962 | friend class Cache; 963 | 964 | VideoFrame(VideoFrameBuffer* _vfb, AVSMap* avsmap, int _offset, int _pitch, int _row_size, int _height); 965 | VideoFrame(VideoFrameBuffer* _vfb, AVSMap* avsmap, int _offset, int _pitch, int _row_size, int _height, int _offsetU, int _offsetV, int _pitchUV, int _row_sizeUV, int _heightUV); 966 | // for Alpha 967 | VideoFrame(VideoFrameBuffer* _vfb, AVSMap* avsmap, int _offset, int _pitch, int _row_size, int _height, int _offsetU, int _offsetV, int _pitchUV, int _row_sizeUV, int _heightUV, int _offsetA); 968 | void* operator new(size_t size); 969 | // TESTME: OFFSET U/V may be switched to what could be expected from AVI standard! 970 | public: 971 | int GetPitch(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetPitch)(plane) ) 972 | int GetRowSize(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetRowSize)(plane) ) 973 | int GetHeight(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetHeight)(plane) ) 974 | 975 | // generally you shouldn't use these three 976 | VideoFrameBuffer* GetFrameBuffer() const AVS_BakedCode( return AVS_LinkCall(GetFrameBuffer)() ) 977 | int GetOffset(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetOffset)(plane) ) 978 | 979 | // in plugins use env->SubFrame() -- because implementation code is only available inside avisynth.dll. Doh! 980 | VideoFrame* Subframe(int rel_offset, int new_pitch, int new_row_size, int new_height) const; 981 | VideoFrame* Subframe(int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int pitchUV) const; 982 | // for Alpha 983 | VideoFrame* Subframe(int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int pitchUV, int rel_offsetA) const; 984 | 985 | const BYTE* GetReadPtr(int plane=0) const AVS_BakedCode( return AVS_LinkCall(VFGetReadPtr)(plane) ) 986 | bool IsWritable() const AVS_BakedCode( return AVS_LinkCall(IsWritable)() ) 987 | BYTE* GetWritePtr(int plane=0) const AVS_BakedCode( return AVS_LinkCall(VFGetWritePtr)(plane) ) 988 | 989 | AVSMap& getProperties() AVS_BakedCode(return AVS_LinkCallOptDefault(getProperties, (AVSMap&)*(AVSMap*)0)) 990 | const AVSMap& getConstProperties() AVS_BakedCode(return AVS_LinkCallOptDefault(getConstProperties, (const AVSMap&)*(const AVSMap*)0)) 991 | void setProperties(const AVSMap & _properties) AVS_BakedCode(AVS_LinkCall_Void(setProperties)(_properties)) 992 | 993 | PDevice GetDevice() const AVS_BakedCode(return AVS_LinkCall(VideoFrame_GetDevice)()) 994 | 995 | // 0: OK, 1: NG, -1: disabled or non CPU frame 996 | int CheckMemory() const AVS_BakedCode(return AVS_LinkCall(VideoFrame_CheckMemory)()) 997 | 998 | ~VideoFrame() AVS_BakedCode( AVS_LinkCall_Void(VideoFrame_DESTRUCTOR)() ) 999 | #ifdef BUILDING_AVSCORE 1000 | public: 1001 | void DESTRUCTOR(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 1002 | #endif 1003 | 1004 | // Ensure VideoFrame cannot be publicly assigned 1005 | private: 1006 | VideoFrame& operator=(const VideoFrame&); 1007 | 1008 | }; // end class VideoFrame 1009 | 1010 | enum CachePolicyHint { 1011 | // Values 0 to 5 are reserved for old 2.5 plugins 1012 | // do not use them in new plugins 1013 | 1014 | // New 2.6 explicitly defined cache hints. 1015 | CACHE_NOTHING=10, // Do not cache video. 1016 | CACHE_WINDOW=11, // Hard protect upto X frames within a range of X from the current frame N. 1017 | CACHE_GENERIC=12, // LRU cache upto X frames. 1018 | CACHE_FORCE_GENERIC=13, // LRU cache upto X frames, override any previous CACHE_WINDOW. 1019 | 1020 | CACHE_GET_POLICY=30, // Get the current policy. 1021 | CACHE_GET_WINDOW=31, // Get the current window h_span. 1022 | CACHE_GET_RANGE=32, // Get the current generic frame range. 1023 | 1024 | CACHE_AUDIO=50, // Explicitly cache audio, X byte cache. 1025 | CACHE_AUDIO_NOTHING=51, // Explicitly do not cache audio. 1026 | CACHE_AUDIO_NONE=52, // Audio cache off (auto mode), X byte intial cache. 1027 | CACHE_AUDIO_AUTO=53, // Audio cache on (auto mode), X byte intial cache. 1028 | 1029 | CACHE_GET_AUDIO_POLICY=70, // Get the current audio policy. 1030 | CACHE_GET_AUDIO_SIZE=71, // Get the current audio cache size. 1031 | 1032 | CACHE_PREFETCH_FRAME=100, // Queue request to prefetch frame N. 1033 | CACHE_PREFETCH_GO=101, // Action video prefetches. 1034 | 1035 | CACHE_PREFETCH_AUDIO_BEGIN=120, // Begin queue request transaction to prefetch audio (take critical section). 1036 | CACHE_PREFETCH_AUDIO_STARTLO=121, // Set low 32 bits of start. 1037 | CACHE_PREFETCH_AUDIO_STARTHI=122, // Set high 32 bits of start. 1038 | CACHE_PREFETCH_AUDIO_COUNT=123, // Set low 32 bits of length. 1039 | CACHE_PREFETCH_AUDIO_COMMIT=124, // Enqueue request transaction to prefetch audio (release critical section). 1040 | CACHE_PREFETCH_AUDIO_GO=125, // Action audio prefetches. 1041 | 1042 | CACHE_GETCHILD_CACHE_MODE=200, // Cache ask Child for desired video cache mode. 1043 | CACHE_GETCHILD_CACHE_SIZE=201, // Cache ask Child for desired video cache size. 1044 | CACHE_GETCHILD_AUDIO_MODE=202, // Cache ask Child for desired audio cache mode. 1045 | CACHE_GETCHILD_AUDIO_SIZE=203, // Cache ask Child for desired audio cache size. 1046 | 1047 | CACHE_GETCHILD_COST=220, // Cache ask Child for estimated processing cost. 1048 | CACHE_COST_ZERO=221, // Child response of zero cost (ptr arithmetic only). 1049 | CACHE_COST_UNIT=222, // Child response of unit cost (less than or equal 1 full frame blit). 1050 | CACHE_COST_LOW=223, // Child response of light cost. (Fast) 1051 | CACHE_COST_MED=224, // Child response of medium cost. (Real time) 1052 | CACHE_COST_HI=225, // Child response of heavy cost. (Slow) 1053 | 1054 | CACHE_GETCHILD_THREAD_MODE=240, // Cache ask Child for thread safetyness. 1055 | CACHE_THREAD_UNSAFE=241, // Only 1 thread allowed for all instances. 2.5 filters default! 1056 | CACHE_THREAD_CLASS=242, // Only 1 thread allowed for each instance. 2.6 filters default! 1057 | CACHE_THREAD_SAFE=243, // Allow all threads in any instance. 1058 | CACHE_THREAD_OWN=244, // Safe but limit to 1 thread, internally threaded. 1059 | 1060 | CACHE_GETCHILD_ACCESS_COST=260, // Cache ask Child for preferred access pattern. 1061 | CACHE_ACCESS_RAND=261, // Filter is access order agnostic. 1062 | CACHE_ACCESS_SEQ0=262, // Filter prefers sequential access (low cost) 1063 | CACHE_ACCESS_SEQ1=263, // Filter needs sequential access (high cost) 1064 | 1065 | CACHE_AVSPLUS_CONSTANTS = 500, // Smaller values are reserved for classic Avisynth 1066 | 1067 | CACHE_DONT_CACHE_ME, // Filters that don't need caching (eg. trim, cache etc.) should return 1 to this request 1068 | CACHE_SET_MIN_CAPACITY, 1069 | CACHE_SET_MAX_CAPACITY, 1070 | CACHE_GET_MIN_CAPACITY, 1071 | CACHE_GET_MAX_CAPACITY, 1072 | CACHE_GET_SIZE, 1073 | CACHE_GET_REQUESTED_CAP, 1074 | CACHE_GET_CAPACITY, 1075 | CACHE_GET_MTMODE, 1076 | 1077 | CACHE_IS_CACHE_REQ, 1078 | CACHE_IS_CACHE_ANS, 1079 | CACHE_IS_MTGUARD_REQ, 1080 | CACHE_IS_MTGUARD_ANS, 1081 | 1082 | CACHE_AVSPLUS_CUDA_CONSTANTS = 600, 1083 | 1084 | CACHE_GET_DEV_TYPE, // Device types a filter can return 1085 | CACHE_GET_CHILD_DEV_TYPE, // Device types a fitler can receive 1086 | 1087 | CACHE_USER_CONSTANTS = 1000 // Smaller values are reserved for the core 1088 | 1089 | }; 1090 | 1091 | // Base class for all filters. 1092 | class IClip { 1093 | friend class PClip; 1094 | friend class AVSValue; 1095 | volatile long refcnt; 1096 | void AddRef(); 1097 | #if BUILDING_AVSCORE 1098 | public: 1099 | #endif 1100 | void Release(); 1101 | public: 1102 | IClip() : refcnt(0) {} 1103 | virtual int __stdcall GetVersion() { return AVISYNTH_INTERFACE_VERSION; } 1104 | virtual PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) = 0; 1105 | virtual bool __stdcall GetParity(int n) = 0; // return field parity if field_based, else parity of first field in frame 1106 | virtual void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env) = 0; // start and count are in samples 1107 | /* Need to check GetVersion first, pre v5 will return random crap from EAX reg. */ 1108 | virtual int __stdcall SetCacheHints(int cachehints,int frame_range) = 0 ; // We do not pass cache requests upwards, only to the next filter. 1109 | virtual const VideoInfo& __stdcall GetVideoInfo() = 0; 1110 | virtual ~IClip() {} 1111 | }; // end class IClip 1112 | 1113 | 1114 | // smart pointer to IClip 1115 | class PClip { 1116 | 1117 | IClip* p; 1118 | 1119 | IClip* GetPointerWithAddRef() const; 1120 | friend class AVSValue; 1121 | friend class VideoFrame; 1122 | 1123 | void Init(IClip* x); 1124 | void Set(IClip* x); 1125 | 1126 | public: 1127 | PClip() AVS_BakedCode( AVS_LinkCall_Void(PClip_CONSTRUCTOR0)() ) 1128 | PClip(const PClip& x) AVS_BakedCode( AVS_LinkCall_Void(PClip_CONSTRUCTOR1)(x) ) 1129 | PClip(IClip* x) AVS_BakedCode( AVS_LinkCall_Void(PClip_CONSTRUCTOR2)(x) ) 1130 | void operator=(IClip* x) AVS_BakedCode( AVS_LinkCall_Void(PClip_OPERATOR_ASSIGN0)(x) ) 1131 | void operator=(const PClip& x) AVS_BakedCode( AVS_LinkCall_Void(PClip_OPERATOR_ASSIGN1)(x) ) 1132 | 1133 | IClip* operator->() const { return p; } 1134 | 1135 | // useful in conditional expressions 1136 | operator void*() const { return p; } 1137 | bool operator!() const { return !p; } 1138 | 1139 | ~PClip() AVS_BakedCode( AVS_LinkCall_Void(PClip_DESTRUCTOR)() ) 1140 | #ifdef BUILDING_AVSCORE 1141 | public: 1142 | void CONSTRUCTOR0(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 1143 | void CONSTRUCTOR1(const PClip& x); 1144 | void CONSTRUCTOR2(IClip* x); 1145 | void OPERATOR_ASSIGN0(IClip* x); 1146 | void OPERATOR_ASSIGN1(const PClip& x); 1147 | void DESTRUCTOR(); 1148 | #endif 1149 | }; // end class PClip 1150 | 1151 | // enums for frame property functions 1152 | enum AVSPropTypes { 1153 | PROPTYPE_UNSET = 'u', // ptUnset 1154 | PROPTYPE_INT = 'i', // peType 1155 | PROPTYPE_FLOAT = 'f', // ptFloat 1156 | PROPTYPE_DATA = 's', // ptData 1157 | PROPTYPE_CLIP = 'c', // ptClip 1158 | PROPTYPE_FRAME = 'v' // ptFrame 1159 | // ptFunction = 'm' 1160 | }; 1161 | 1162 | enum AVSGetPropErrors { 1163 | GETPROPERROR_UNSET = 1, // peUnset 1164 | GETPROPERROR_TYPE = 2, // peType 1165 | GETPROPERROR_INDEX = 4 // peIndex 1166 | }; 1167 | 1168 | enum AVSPropAppendMode { 1169 | PROPAPPENDMODE_REPLACE = 0, // paReplace 1170 | PROPAPPENDMODE_APPEND = 1, // paAppend 1171 | PROPAPPENDMODE_TOUCH = 2 // paTouch 1172 | }; 1173 | 1174 | 1175 | class AVSValue { 1176 | public: 1177 | 1178 | AVSValue() AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR0)() ) 1179 | AVSValue(IClip* c) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR1)(c) ) 1180 | AVSValue(const PClip& c) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR2)(c) ) 1181 | AVSValue(bool b) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR3)(b) ) 1182 | AVSValue(int i) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR4)(i) ) 1183 | // AVSValue(int64_t l); 1184 | AVSValue(float f) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR5)(f) ) 1185 | AVSValue(double f) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR6)(f) ) 1186 | AVSValue(const char* s) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR7)(s) ) 1187 | AVSValue(const AVSValue* a, int size) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR8)(a, size) ) 1188 | AVSValue(const AVSValue& a, int size) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR8)(&a, size) ) 1189 | AVSValue(const AVSValue& v) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR9)(v) ) 1190 | AVSValue(const PFunction& n) AVS_BakedCode(AVS_LinkCall_Void(AVSValue_CONSTRUCTOR11)(n)) 1191 | 1192 | ~AVSValue() AVS_BakedCode( AVS_LinkCall_Void(AVSValue_DESTRUCTOR)() ) 1193 | AVSValue& operator=(const AVSValue& v) AVS_BakedCode( return AVS_LinkCallV(AVSValue_OPERATOR_ASSIGN)(v) ) 1194 | 1195 | // Note that we transparently allow 'int' to be treated as 'float'. 1196 | // There are no int<->bool conversions, though. 1197 | 1198 | bool Defined() const AVS_BakedCode( return AVS_LinkCall(Defined)() ) 1199 | bool IsClip() const AVS_BakedCode( return AVS_LinkCall(IsClip)() ) 1200 | bool IsBool() const AVS_BakedCode( return AVS_LinkCall(IsBool)() ) 1201 | bool IsInt() const AVS_BakedCode( return AVS_LinkCall(IsInt)() ) 1202 | // bool IsLong() const; 1203 | bool IsFloat() const AVS_BakedCode( return AVS_LinkCall(IsFloat)() ) 1204 | bool IsString() const AVS_BakedCode( return AVS_LinkCall(IsString)() ) 1205 | bool IsArray() const AVS_BakedCode(return AVS_LinkCall(IsArray)()) 1206 | bool IsFunction() const AVS_BakedCode( return AVS_LinkCall(IsFunction)() ) 1207 | 1208 | PClip AsClip() const AVS_BakedCode( return AVS_LinkCall(AsClip)() ) 1209 | bool AsBool() const AVS_BakedCode( return AVS_LinkCall(AsBool1)() ) 1210 | int AsInt() const AVS_BakedCode( return AVS_LinkCall(AsInt1)() ) 1211 | // int AsLong() const; 1212 | const char* AsString() const AVS_BakedCode( return AVS_LinkCall(AsString1)() ) 1213 | double AsFloat() const AVS_BakedCode( return AVS_LinkCall(AsFloat1)() ) 1214 | float AsFloatf() const AVS_BakedCode( return float( AVS_LinkCall(AsFloat1)() ) ) 1215 | 1216 | bool AsBool(bool def) const AVS_BakedCode( return AVS_LinkCall(AsBool2)(def) ) 1217 | int AsInt(int def) const AVS_BakedCode( return AVS_LinkCall(AsInt2)(def) ) 1218 | double AsDblDef(double def) const AVS_BakedCode( return AVS_LinkCall(AsDblDef)(def) ) // Value is still a float 1219 | double AsFloat(float def) const AVS_BakedCode( return AVS_LinkCall(AsFloat2)(def) ) 1220 | float AsFloatf(float def) const AVS_BakedCode( return float( AVS_LinkCall(AsFloat2)(def) ) ) 1221 | const char* AsString(const char* def) const AVS_BakedCode( return AVS_LinkCall(AsString2)(def) ) 1222 | PFunction AsFunction() const; // internal use only 1223 | 1224 | int ArraySize() const AVS_BakedCode( return AVS_LinkCall(ArraySize)() ) 1225 | 1226 | const AVSValue& operator[](int index) const AVS_BakedCode( return AVS_LinkCallV(AVSValue_OPERATOR_INDEX)(index) ) 1227 | 1228 | private: 1229 | 1230 | short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, fu'n'ction, or RFU: 'l'ong ('d'ouble) 1231 | short array_size; 1232 | union { 1233 | IClip* clip; 1234 | bool boolean; 1235 | int integer; 1236 | float floating_pt; 1237 | const char* string; 1238 | const AVSValue* array; 1239 | IFunction* function; 1240 | #ifdef X86_64 1241 | // if ever, only x64 will support. It breaks struct size on 32 bit 1242 | int64_t longlong; // 8 bytes 1243 | double double_pt; // 8 bytes 1244 | #endif 1245 | }; 1246 | 1247 | void Assign(const AVSValue* src, bool init); 1248 | #ifdef BUILDING_AVSCORE 1249 | public: 1250 | void CONSTRUCTOR0(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 1251 | void CONSTRUCTOR1(IClip* c); 1252 | void CONSTRUCTOR2(const PClip& c); 1253 | void CONSTRUCTOR3(bool b); 1254 | void CONSTRUCTOR4(int i); 1255 | void CONSTRUCTOR5(float f); 1256 | void CONSTRUCTOR6(double f); 1257 | void CONSTRUCTOR7(const char* s); 1258 | void CONSTRUCTOR8(const AVSValue* a, int size); 1259 | void CONSTRUCTOR9(const AVSValue& v); 1260 | void CONSTRUCTOR11(const PFunction& n); 1261 | void DESTRUCTOR(); 1262 | AVSValue& OPERATOR_ASSIGN(const AVSValue& v); 1263 | const AVSValue& OPERATOR_INDEX(int index) const; 1264 | 1265 | bool AsBool1() const; 1266 | int AsInt1() const; 1267 | const char* AsString1() const; 1268 | double AsFloat1() const; 1269 | 1270 | bool AsBool2(bool def) const; 1271 | int AsInt2(int def) const; 1272 | double AsFloat2(float def) const; 1273 | const char* AsString2(const char* def) const; 1274 | 1275 | #ifdef NEW_AVSVALUE 1276 | void MarkArrayAsC(); // for C interface, no deep-copy and deep-free 1277 | void CONSTRUCTOR10(const AVSValue& v, bool c_arrays); 1278 | AVSValue(const AVSValue& v, bool c_arrays); 1279 | void Assign2(const AVSValue* src, bool init, bool c_arrays); 1280 | #endif 1281 | 1282 | #endif 1283 | }; // end class AVSValue 1284 | 1285 | #define AVS_UNUSED(x) (void)(x) 1286 | 1287 | // instantiable null filter 1288 | class GenericVideoFilter : public IClip { 1289 | protected: 1290 | PClip child; 1291 | VideoInfo vi; 1292 | public: 1293 | GenericVideoFilter(PClip _child) : child(_child) { vi = child->GetVideoInfo(); } 1294 | PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) { return child->GetFrame(n, env); } 1295 | void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env) { child->GetAudio(buf, start, count, env); } 1296 | const VideoInfo& __stdcall GetVideoInfo() { return vi; } 1297 | bool __stdcall GetParity(int n) { return child->GetParity(n); } 1298 | int __stdcall SetCacheHints(int cachehints, int frame_range) { AVS_UNUSED(cachehints); AVS_UNUSED(frame_range); return 0; }; // We do not pass cache requests upwards, only to the next filter. 1299 | }; 1300 | 1301 | 1302 | class PFunction 1303 | { 1304 | public: 1305 | PFunction() AVS_BakedCode(AVS_LinkCall_Void(PFunction_CONSTRUCTOR0)()) 1306 | PFunction(IFunction* p) AVS_BakedCode(AVS_LinkCall_Void(PFunction_CONSTRUCTOR1)(p)) 1307 | PFunction(const PFunction& p) AVS_BakedCode(AVS_LinkCall_Void(PFunction_CONSTRUCTOR2)(p)) 1308 | PFunction& operator=(IFunction* p) AVS_BakedCode(return AVS_LinkCallV(PFunction_OPERATOR_ASSIGN0)(p)) 1309 | PFunction& operator=(const PFunction& p) AVS_BakedCode(return AVS_LinkCallV(PFunction_OPERATOR_ASSIGN1)(p)) 1310 | ~PFunction() AVS_BakedCode(AVS_LinkCall_Void(PFunction_DESTRUCTOR)()) 1311 | 1312 | int operator!() const { return !e; } 1313 | operator void*() const { return e; } 1314 | IFunction* operator->() const { return e; } 1315 | 1316 | private: 1317 | IFunction * e; 1318 | 1319 | friend class AVSValue; 1320 | IFunction * GetPointerWithAddRef() const; 1321 | void Init(IFunction* p); 1322 | void Set(IFunction* p); 1323 | 1324 | #ifdef BUILDING_AVSCORE 1325 | public: 1326 | void CONSTRUCTOR0(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 1327 | void CONSTRUCTOR1(IFunction* p); 1328 | void CONSTRUCTOR2(const PFunction& p); 1329 | PFunction& OPERATOR_ASSIGN0(IFunction* p); 1330 | PFunction& OPERATOR_ASSIGN1(const PFunction& p); 1331 | void DESTRUCTOR(); 1332 | #endif 1333 | }; 1334 | 1335 | 1336 | #undef CALL_MEMBER_FN 1337 | #undef AVS_LinkCallOptDefault 1338 | #undef AVS_LinkCallOpt 1339 | #undef AVS_LinkCallV 1340 | #undef AVS_LinkCall 1341 | #undef AVS_BakedCode 1342 | 1343 | 1344 | #include "avs/cpuid.h" 1345 | 1346 | // IScriptEnvironment GetEnvProperty 1347 | enum AvsEnvProperty 1348 | { 1349 | AEP_PHYSICAL_CPUS = 1, 1350 | AEP_LOGICAL_CPUS = 2, 1351 | AEP_THREADPOOL_THREADS = 3, 1352 | AEP_FILTERCHAIN_THREADS = 4, 1353 | AEP_THREAD_ID = 5, 1354 | AEP_VERSION = 6, 1355 | 1356 | // Neo additionals 1357 | AEP_NUM_DEVICES = 901, 1358 | AEP_FRAME_ALIGN = 902, 1359 | AEP_PLANE_ALIGN = 903, 1360 | 1361 | AEP_SUPPRESS_THREAD = 921, 1362 | AEP_GETFRAME_RECURSIVE = 922, 1363 | }; 1364 | 1365 | // IScriptEnvironment Allocate 1366 | enum AvsAllocType 1367 | { 1368 | AVS_NORMAL_ALLOC = 1, 1369 | AVS_POOLED_ALLOC = 2 1370 | }; 1371 | 1372 | 1373 | class IScriptEnvironment { 1374 | public: 1375 | virtual ~IScriptEnvironment() {} 1376 | 1377 | virtual /*static*/ int __stdcall GetCPUFlags() = 0; 1378 | 1379 | virtual char* __stdcall SaveString(const char* s, int length = -1) = 0; 1380 | virtual char* Sprintf(const char* fmt, ...) = 0; 1381 | // note: val is really a va_list; I hope everyone typedefs va_list to a pointer 1382 | // 20200305: (void *) changed back to va_list 1383 | virtual char* __stdcall VSprintf(const char* fmt, va_list val) = 0; 1384 | 1385 | #ifdef AVS_WINDOWS 1386 | __declspec(noreturn) virtual void ThrowError(const char* fmt, ...) = 0; 1387 | #else 1388 | virtual void ThrowError(const char* fmt, ...) = 0; 1389 | #endif 1390 | 1391 | class NotFound /*exception*/ {}; // thrown by Invoke and GetVar 1392 | 1393 | typedef AVSValue (__cdecl *ApplyFunc)(AVSValue args, void* user_data, IScriptEnvironment* env); 1394 | 1395 | virtual void __stdcall AddFunction(const char* name, const char* params, ApplyFunc apply, void* user_data) = 0; 1396 | virtual bool __stdcall FunctionExists(const char* name) = 0; 1397 | virtual AVSValue __stdcall Invoke(const char* name, const AVSValue args, const char* const* arg_names=0) = 0; 1398 | 1399 | virtual AVSValue __stdcall GetVar(const char* name) = 0; 1400 | virtual bool __stdcall SetVar(const char* name, const AVSValue& val) = 0; 1401 | virtual bool __stdcall SetGlobalVar(const char* name, const AVSValue& val) = 0; 1402 | 1403 | virtual void __stdcall PushContext(int level=0) = 0; 1404 | virtual void __stdcall PopContext() = 0; 1405 | 1406 | // note v8: deprecated in most cases, use NewVideoFrameP is possible 1407 | virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi, int align=FRAME_ALIGN) = 0; 1408 | 1409 | virtual bool __stdcall MakeWritable(PVideoFrame* pvf) = 0; 1410 | 1411 | virtual void __stdcall BitBlt(BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height) = 0; 1412 | 1413 | typedef void (__cdecl *ShutdownFunc)(void* user_data, IScriptEnvironment* env); 1414 | virtual void __stdcall AtExit(ShutdownFunc function, void* user_data) = 0; 1415 | 1416 | virtual void __stdcall CheckVersion(int version = AVISYNTH_INTERFACE_VERSION) = 0; 1417 | 1418 | virtual PVideoFrame __stdcall Subframe(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, int new_height) = 0; 1419 | 1420 | virtual int __stdcall SetMemoryMax(int mem) = 0; 1421 | 1422 | virtual int __stdcall SetWorkingDir(const char * newdir) = 0; 1423 | 1424 | virtual void* __stdcall ManageCache(int key, void* data) = 0; 1425 | 1426 | enum PlanarChromaAlignmentMode { 1427 | PlanarChromaAlignmentOff, 1428 | PlanarChromaAlignmentOn, 1429 | PlanarChromaAlignmentTest }; 1430 | 1431 | virtual bool __stdcall PlanarChromaAlignment(PlanarChromaAlignmentMode key) = 0; 1432 | 1433 | virtual PVideoFrame __stdcall SubframePlanar(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, 1434 | int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV) = 0; 1435 | 1436 | // **** AVISYNTH_INTERFACE_VERSION 5 **** defined since classic Avisynth 2.6 beta 1437 | virtual void __stdcall DeleteScriptEnvironment() = 0; 1438 | 1439 | virtual void __stdcall ApplyMessage(PVideoFrame* frame, const VideoInfo& vi, const char* message, int size, 1440 | int textcolor, int halocolor, int bgcolor) = 0; 1441 | 1442 | virtual const AVS_Linkage* __stdcall GetAVSLinkage() = 0; 1443 | 1444 | // **** AVISYNTH_INTERFACE_VERSION 6 **** defined since classic Avisynth 2.6 1445 | // noThrow version of GetVar 1446 | virtual AVSValue __stdcall GetVarDef(const char* name, const AVSValue& def = AVSValue()) = 0; 1447 | 1448 | // **** AVISYNTH_INTERFACE_VERSION 8 **** AviSynth+ 3.6.0- 1449 | virtual PVideoFrame __stdcall SubframePlanarA(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, 1450 | int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV, int rel_offsetA) = 0; 1451 | 1452 | virtual void __stdcall copyFrameProps(const PVideoFrame& src, PVideoFrame& dst) = 0; 1453 | virtual const AVSMap* __stdcall getFramePropsRO(const PVideoFrame& frame) = 0; 1454 | virtual AVSMap* __stdcall getFramePropsRW(PVideoFrame& frame) = 0; 1455 | 1456 | virtual int __stdcall propNumKeys(const AVSMap* map) = 0; 1457 | 1458 | virtual const char* __stdcall propGetKey(const AVSMap* map, int index) = 0; 1459 | virtual int __stdcall propNumElements(const AVSMap* map, const char* key) = 0; 1460 | virtual char __stdcall propGetType(const AVSMap* map, const char* key) = 0; 1461 | 1462 | virtual int64_t __stdcall propGetInt(const AVSMap* map, const char* key, int index, int* error) = 0; 1463 | virtual double __stdcall propGetFloat(const AVSMap* map, const char* key, int index, int* error) = 0; 1464 | virtual const char* __stdcall propGetData(const AVSMap* map, const char* key, int index, int* error) = 0; 1465 | virtual int __stdcall propGetDataSize(const AVSMap* map, const char* key, int index, int* error) = 0; 1466 | virtual PClip __stdcall propGetClip(const AVSMap* map, const char* key, int index, int* error) = 0; 1467 | virtual const PVideoFrame __stdcall propGetFrame(const AVSMap* map, const char* key, int index, int* error) = 0; 1468 | 1469 | virtual int __stdcall propDeleteKey(AVSMap* map, const char* key) = 0; 1470 | 1471 | virtual int __stdcall propSetInt(AVSMap* map, const char* key, int64_t i, int append) = 0; 1472 | virtual int __stdcall propSetFloat(AVSMap* map, const char* key, double d, int append) = 0; 1473 | virtual int __stdcall propSetData(AVSMap* map, const char* key, const char* d, int length, int append) = 0; 1474 | virtual int __stdcall propSetClip(AVSMap* map, const char* key, PClip& clip, int append) = 0; 1475 | virtual int __stdcall propSetFrame(AVSMap* map, const char* key, const PVideoFrame& frame, int append) = 0; 1476 | 1477 | virtual const int64_t* __stdcall propGetIntArray(const AVSMap* map, const char* key, int* error) = 0; 1478 | virtual const double* __stdcall propGetFloatArray(const AVSMap* map, const char* key, int* error) = 0; 1479 | virtual int __stdcall propSetIntArray(AVSMap* map, const char* key, const int64_t* i, int size) = 0; 1480 | virtual int __stdcall propSetFloatArray(AVSMap* map, const char* key, const double* d, int size) = 0; 1481 | 1482 | virtual AVSMap* __stdcall createMap() = 0; 1483 | virtual void __stdcall freeMap(AVSMap* map) = 0; 1484 | virtual void __stdcall clearMap(AVSMap* map) = 0; 1485 | 1486 | // NewVideoFrame with frame property source. 1487 | virtual PVideoFrame __stdcall NewVideoFrameP(const VideoInfo& vi, PVideoFrame* propSrc, int align = FRAME_ALIGN) = 0; 1488 | 1489 | // Note: do not declare existing names like 'NewVideoFrame' again with different parameters since MSVC will reorder it 1490 | // in the vtable and group it together with the first NewVideoFrame variant. 1491 | // This results in shifting all vtable method pointers after NewVideoFrame and breaks all plugins who expect the old order. 1492 | // E.g. ApplyMessage will be called instead of GetAVSLinkage 1493 | 1494 | // Generic query to ask for various system properties 1495 | virtual size_t __stdcall GetEnvProperty(AvsEnvProperty prop) = 0; 1496 | 1497 | // Support functions 1498 | virtual void* __stdcall Allocate(size_t nBytes, size_t alignment, AvsAllocType type) = 0; 1499 | virtual void __stdcall Free(void* ptr) = 0; 1500 | 1501 | // these GetVar versions (renamed differently) were moved from IScriptEnvironment2 1502 | 1503 | // Returns TRUE and the requested variable. If the method fails, returns FALSE and does not touch 'val'. 1504 | virtual bool __stdcall GetVarTry(const char* name, AVSValue* val) const = 0; // ex virtual bool __stdcall GetVar(const char* name, AVSValue* val) const = 0; 1505 | // Return the value of the requested variable. 1506 | // If the variable was not found or had the wrong type, 1507 | // return the supplied default value. 1508 | virtual bool __stdcall GetVarBool(const char* name, bool def) const = 0; 1509 | virtual int __stdcall GetVarInt(const char* name, int def) const = 0; 1510 | virtual double __stdcall GetVarDouble(const char* name, double def) const = 0; 1511 | virtual const char* __stdcall GetVarString(const char* name, const char* def) const = 0; 1512 | // brand new in v8 - though no real int64 support yet 1513 | virtual int64_t __stdcall GetVarLong(const char* name, int64_t def) const = 0; 1514 | 1515 | // 'Invoke' functions moved here from internal ScriptEnvironments are renamed in order to keep vtable order 1516 | // Invoke functions with 'Try' will return false instead of throwing NotFound(). 1517 | // ex-IScriptEnvironment2 1518 | virtual bool __stdcall InvokeTry(AVSValue* result, const char* name, const AVSValue& args, const char* const* arg_names = 0) = 0; 1519 | // Since V8 1520 | virtual AVSValue __stdcall Invoke2(const AVSValue& implicit_last, const char* name, const AVSValue args, const char* const* arg_names = 0) = 0; 1521 | // Ex-INeo 1522 | virtual bool __stdcall Invoke2Try(AVSValue* result, const AVSValue& implicit_last, const char* name, const AVSValue args, const char* const* arg_names = 0) = 0; 1523 | virtual AVSValue __stdcall Invoke3(const AVSValue& implicit_last, const PFunction& func, const AVSValue args, const char* const* arg_names = 0) = 0; 1524 | virtual bool __stdcall Invoke3Try(AVSValue* result, const AVSValue& implicit_last, const PFunction& func, const AVSValue args, const char* const* arg_names = 0) = 0; 1525 | 1526 | }; // end class IScriptEnvironment 1527 | 1528 | // used internally 1529 | class IScriptEnvironment_Avs25 { 1530 | public: 1531 | virtual ~IScriptEnvironment_Avs25() {} 1532 | 1533 | virtual /*static*/ int __stdcall GetCPUFlags() = 0; 1534 | 1535 | virtual char* __stdcall SaveString(const char* s, int length = -1) = 0; 1536 | virtual char* Sprintf(const char* fmt, ...) = 0; 1537 | virtual char* __stdcall VSprintf(const char* fmt, va_list val) = 0; 1538 | 1539 | #ifdef AVS_WINDOWS 1540 | __declspec(noreturn) virtual void ThrowError(const char* fmt, ...) = 0; 1541 | #else 1542 | virtual void ThrowError(const char* fmt, ...) = 0; 1543 | #endif 1544 | 1545 | class NotFound /*exception*/ {}; // thrown by Invoke and GetVar 1546 | 1547 | typedef AVSValue(__cdecl* ApplyFunc)(AVSValue args, void* user_data, IScriptEnvironment* env); 1548 | 1549 | virtual void __stdcall AddFunction25(const char* name, const char* params, ApplyFunc apply, void* user_data) = 0; 1550 | virtual bool __stdcall FunctionExists(const char* name) = 0; 1551 | virtual AVSValue __stdcall Invoke25(const char* name, const AVSValue args, const char* const* arg_names = 0) = 0; 1552 | 1553 | virtual AVSValue __stdcall GetVar(const char* name) = 0; 1554 | virtual bool __stdcall SetVar(const char* name, const AVSValue& val) = 0; 1555 | virtual bool __stdcall SetGlobalVar(const char* name, const AVSValue& val) = 0; 1556 | 1557 | virtual void __stdcall PushContext(int level = 0) = 0; 1558 | virtual void __stdcall PopContext() = 0; 1559 | 1560 | virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi, int align = FRAME_ALIGN) = 0; 1561 | 1562 | virtual bool __stdcall MakeWritable(PVideoFrame* pvf) = 0; 1563 | 1564 | virtual void __stdcall BitBlt(BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height) = 0; 1565 | 1566 | typedef void(__cdecl* ShutdownFunc)(void* user_data, IScriptEnvironment* env); 1567 | virtual void __stdcall AtExit(ShutdownFunc function, void* user_data) = 0; 1568 | 1569 | virtual void __stdcall CheckVersion(int version = AVISYNTH_CLASSIC_INTERFACE_VERSION_25) = 0; 1570 | 1571 | virtual PVideoFrame __stdcall Subframe(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, int new_height) = 0; 1572 | 1573 | virtual int __stdcall SetMemoryMax(int mem) = 0; 1574 | 1575 | virtual int __stdcall SetWorkingDir(const char* newdir) = 0; 1576 | 1577 | // specially returns 1 for key MC_QueryAvs25 to check if called from AVS2.5 interface 1578 | virtual void* __stdcall ManageCache25(int key, void* data) = 0; 1579 | 1580 | enum PlanarChromaAlignmentMode { 1581 | PlanarChromaAlignmentOff, 1582 | PlanarChromaAlignmentOn, 1583 | PlanarChromaAlignmentTest 1584 | }; 1585 | 1586 | virtual bool __stdcall PlanarChromaAlignment(IScriptEnvironment::PlanarChromaAlignmentMode key) = 0; 1587 | 1588 | virtual PVideoFrame __stdcall SubframePlanar(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, 1589 | int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV) = 0; 1590 | 1591 | // Despite the name, we provide entries up to V6 in case someone requests 1592 | // a V3 interface and still wants to use V5-V6 functions 1593 | 1594 | // **** AVISYNTH_INTERFACE_VERSION 5 **** defined since classic Avisynth 2.6 beta 1595 | virtual void __stdcall DeleteScriptEnvironment() = 0; 1596 | 1597 | virtual void __stdcall ApplyMessage(PVideoFrame* frame, const VideoInfo& vi, const char* message, int size, 1598 | int textcolor, int halocolor, int bgcolor) = 0; 1599 | 1600 | virtual const AVS_Linkage* __stdcall GetAVSLinkage() = 0; 1601 | 1602 | // **** AVISYNTH_INTERFACE_VERSION 6 **** defined since classic Avisynth 2.6 1603 | // noThrow version of GetVar 1604 | virtual AVSValue __stdcall GetVarDef(const char* name, const AVSValue& def = AVSValue()) = 0; 1605 | 1606 | }; // end class IScriptEnvironment_Avs25 1607 | 1608 | 1609 | enum MtMode 1610 | { 1611 | MT_INVALID = 0, 1612 | MT_NICE_FILTER = 1, 1613 | MT_MULTI_INSTANCE = 2, 1614 | MT_SERIALIZED = 3, 1615 | MT_SPECIAL_MT = 4, 1616 | MT_MODE_COUNT = 5 1617 | }; 1618 | 1619 | class IJobCompletion 1620 | { 1621 | public: 1622 | 1623 | virtual ~IJobCompletion() {} 1624 | virtual void __stdcall Wait() = 0; 1625 | virtual AVSValue __stdcall Get(size_t i) = 0; 1626 | virtual size_t __stdcall Size() const = 0; 1627 | virtual size_t __stdcall Capacity() const = 0; 1628 | virtual void __stdcall Reset() = 0; 1629 | virtual void __stdcall Destroy() = 0; 1630 | }; 1631 | 1632 | class IScriptEnvironment2; 1633 | class Prefetcher; 1634 | typedef AVSValue (*ThreadWorkerFuncPtr)(IScriptEnvironment2* env, void* data); 1635 | 1636 | 1637 | /* ----------------------------------------------------------------------------- 1638 | Note to plugin authors: The interface in IScriptEnvironment2 is 1639 | preliminary / under construction / only for testing / non-final etc.! 1640 | As long as you see this note here, IScriptEnvironment2 might still change, 1641 | in which case your plugin WILL break. This also means that you are welcome 1642 | to test it and give your feedback about any ideas, improvements, or issues 1643 | you might have. 1644 | ----------------------------------------------------------------------------- */ 1645 | class IScriptEnvironment2 : public IScriptEnvironment{ 1646 | public: 1647 | virtual ~IScriptEnvironment2() {} 1648 | 1649 | // V8: SubframePlanarA, GetEnvProperty, GetVar versions, Allocate, Free, no-throw Invoke moved to IScriptEnvironment 1650 | 1651 | // Plugin functions 1652 | virtual bool __stdcall LoadPlugin(const char* filePath, bool throwOnError, AVSValue *result) = 0; 1653 | virtual void __stdcall AddAutoloadDir(const char* dirPath, bool toFront) = 0; 1654 | virtual void __stdcall ClearAutoloadDirs() = 0; 1655 | virtual void __stdcall AutoloadPlugins() = 0; 1656 | virtual void __stdcall AddFunction(const char* name, const char* params, ApplyFunc apply, void* user_data, const char *exportVar) = 0; 1657 | virtual bool __stdcall InternalFunctionExists(const char* name) = 0; 1658 | 1659 | // Threading 1660 | virtual void __stdcall SetFilterMTMode(const char* filter, MtMode mode, bool force) = 0; // If filter is "DEFAULT_MT_MODE", sets the default MT mode 1661 | virtual IJobCompletion* __stdcall NewCompletion(size_t capacity) = 0; 1662 | virtual void __stdcall ParallelJob(ThreadWorkerFuncPtr jobFunc, void* jobData, IJobCompletion* completion) = 0; 1663 | 1664 | // These lines are needed so that we can overload the older functions from IScriptEnvironment. 1665 | using IScriptEnvironment::Invoke; 1666 | using IScriptEnvironment::AddFunction; 1667 | 1668 | }; // end class IScriptEnvironment2 1669 | 1670 | 1671 | // To allow Avisynth+ add functions to IScriptEnvironment2, 1672 | // Neo defines another new interface, INeoEnv. 1673 | // INeoEnv and the legacy interfaces (IScriptEnvironment/IScriptEnvironment2) 1674 | // share the same ScriptEnvironment instance. The function with the same signature 1675 | // is exactly identical and there is no limitation to switch interfaces. 1676 | // You can use any interface you like. 1677 | class INeoEnv { 1678 | public: 1679 | virtual ~INeoEnv() {} 1680 | 1681 | typedef IScriptEnvironment::NotFound NotFound; 1682 | typedef IScriptEnvironment::ApplyFunc ApplyFunc; 1683 | typedef IScriptEnvironment::ShutdownFunc ShutdownFunc; 1684 | 1685 | virtual void __stdcall DeleteScriptEnvironment() = 0; 1686 | 1687 | virtual const AVS_Linkage* __stdcall GetAVSLinkage() = 0; 1688 | 1689 | // Get legacy interface (Avisynth+) 1690 | virtual IScriptEnvironment2* __stdcall GetEnv2() = 0; 1691 | // Get compatibility interface for AVS CPP 2.5 plugins 1692 | virtual IScriptEnvironment_Avs25* __stdcall GetEnv25() = 0; 1693 | 1694 | // Generic system to ask for various properties 1695 | virtual size_t __stdcall GetEnvProperty(AvsEnvProperty prop) = 0; 1696 | #ifdef INTEL_INTRINSICS 1697 | virtual int __stdcall GetCPUFlags() = 0; 1698 | #endif 1699 | 1700 | // Plugin functions 1701 | virtual bool __stdcall LoadPlugin(const char* filePath, bool throwOnError, AVSValue *result) = 0; 1702 | virtual void __stdcall AddAutoloadDir(const char* dirPath, bool toFront) = 0; 1703 | virtual void __stdcall ClearAutoloadDirs() = 0; 1704 | virtual void __stdcall AutoloadPlugins() = 0; 1705 | 1706 | virtual void __stdcall AddFunction( 1707 | const char* name, const char* params, ApplyFunc apply, void* user_data) = 0; 1708 | virtual void __stdcall AddFunction( 1709 | const char* name, const char* params, ApplyFunc apply, void* user_data, const char *exportVar) = 0; 1710 | virtual bool __stdcall FunctionExists(const char* name) = 0; 1711 | virtual bool __stdcall InternalFunctionExists(const char* name) = 0; 1712 | 1713 | // Invoke function. Throws NotFound exception when the specified function does not exist. 1714 | virtual AVSValue __stdcall Invoke( 1715 | const char* name, const AVSValue args, const char* const* arg_names = 0) = 0; 1716 | virtual AVSValue __stdcall Invoke2( 1717 | const AVSValue& implicit_last, const char* name, const AVSValue args, const char* const* arg_names = 0) = 0; 1718 | virtual AVSValue __stdcall Invoke3( 1719 | const AVSValue& implicit_last, 1720 | const PFunction& func, const AVSValue args, const char* const* arg_names = 0) = 0; 1721 | 1722 | // These versions of Invoke will return false instead of throwing NotFound(). 1723 | virtual bool __stdcall InvokeTry( 1724 | AVSValue* result, const char* name, const AVSValue& args, const char* const* arg_names = 0) = 0; 1725 | virtual bool __stdcall Invoke2Try( 1726 | AVSValue* result, const AVSValue& implicit_last, 1727 | const char* name, const AVSValue args, const char* const* arg_names = 0) = 0; 1728 | virtual bool __stdcall Invoke3Try( 1729 | AVSValue* result, const AVSValue& implicit_last, 1730 | const PFunction& func, const AVSValue args, const char* const* arg_names = 0) = 0; 1731 | 1732 | // Throws exception when the requested variable is not found. 1733 | virtual AVSValue __stdcall GetVar(const char* name) = 0; 1734 | 1735 | // noThrow version of GetVar 1736 | virtual AVSValue __stdcall GetVarDef(const char* name, const AVSValue& def = AVSValue()) = 0; 1737 | 1738 | // Returns TRUE and the requested variable. If the method fails, returns FALSE and does not touch 'val'. 1739 | virtual bool __stdcall GetVarTry(const char* name, AVSValue* val) const = 0; 1740 | 1741 | // Return the value of the requested variable. 1742 | // If the variable was not found or had the wrong type, 1743 | // return the supplied default value. 1744 | virtual bool __stdcall GetVarBool(const char* name, bool def) const = 0; 1745 | virtual int __stdcall GetVarInt(const char* name, int def) const = 0; 1746 | virtual double __stdcall GetVarDouble(const char* name, double def) const = 0; 1747 | virtual const char* __stdcall GetVarString(const char* name, const char* def) const = 0; 1748 | virtual int64_t __stdcall GetVarLong(const char* name, int64_t def) const = 0; 1749 | 1750 | virtual bool __stdcall SetVar(const char* name, const AVSValue& val) = 0; 1751 | virtual bool __stdcall SetGlobalVar(const char* name, const AVSValue& val) = 0; 1752 | 1753 | // Switch local variables 1754 | virtual void __stdcall PushContext(int level = 0) = 0; 1755 | virtual void __stdcall PopContext() = 0; 1756 | 1757 | // Global variable frame support 1758 | virtual void __stdcall PushContextGlobal() = 0; 1759 | virtual void __stdcall PopContextGlobal() = 0; 1760 | 1761 | // Allocate new video frame 1762 | // Align parameter is no longer supported 1763 | virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi) = 0; // current device is used 1764 | virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi, const PDevice& device) = 0; 1765 | // as above but with property sources 1766 | virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi, PVideoFrame *propSrc) = 0; // current device is used + frame property source 1767 | virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi, const PDevice& device, PVideoFrame* propSrc) = 0; // current device is used + frame property source 1768 | 1769 | // Frame related operations 1770 | virtual bool __stdcall MakeWritable(PVideoFrame* pvf) = 0; 1771 | virtual void __stdcall BitBlt(BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height) = 0; 1772 | 1773 | virtual PVideoFrame __stdcall Subframe(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, int new_height) = 0; 1774 | virtual PVideoFrame __stdcall SubframePlanar(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, 1775 | int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV) = 0; 1776 | virtual PVideoFrame __stdcall SubframePlanarA(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, 1777 | int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV, int rel_offsetA) = 0; 1778 | 1779 | // frame properties support 1780 | virtual void __stdcall copyFrameProps(const PVideoFrame& src, PVideoFrame& dst) = 0; 1781 | virtual const AVSMap* __stdcall getFramePropsRO(const PVideoFrame& frame) = 0; 1782 | virtual AVSMap* __stdcall getFramePropsRW(PVideoFrame& frame) = 0; 1783 | 1784 | virtual int __stdcall propNumKeys(const AVSMap* map) = 0; 1785 | virtual const char* __stdcall propGetKey(const AVSMap* map, int index) = 0; 1786 | virtual int __stdcall propNumElements(const AVSMap* map, const char* key) = 0; 1787 | virtual char __stdcall propGetType(const AVSMap* map, const char* key) = 0; 1788 | 1789 | virtual int64_t __stdcall propGetInt(const AVSMap* map, const char* key, int index, int* error) = 0; 1790 | virtual double __stdcall propGetFloat(const AVSMap* map, const char* key, int index, int* error) = 0; 1791 | virtual const char* __stdcall propGetData(const AVSMap* map, const char* key, int index, int* error) = 0; 1792 | virtual int __stdcall propGetDataSize(const AVSMap* map, const char* key, int index, int* error) = 0; 1793 | virtual PClip __stdcall propGetClip(const AVSMap* map, const char* key, int index, int* error) = 0; 1794 | virtual const PVideoFrame __stdcall propGetFrame(const AVSMap* map, const char* key, int index, int* error) = 0; 1795 | 1796 | virtual int __stdcall propDeleteKey(AVSMap* map, const char* key) = 0; 1797 | 1798 | virtual int __stdcall propSetInt(AVSMap* map, const char* key, int64_t i, int append) = 0; 1799 | virtual int __stdcall propSetFloat(AVSMap* map, const char* key, double d, int append) = 0; 1800 | virtual int __stdcall propSetData(AVSMap* map, const char* key, const char* d, int length, int append) = 0; 1801 | virtual int __stdcall propSetClip(AVSMap* map, const char* key, PClip& clip, int append) = 0; 1802 | virtual int __stdcall propSetFrame(AVSMap* map, const char* key, const PVideoFrame& frame, int append) = 0; 1803 | 1804 | virtual const int64_t *__stdcall propGetIntArray(const AVSMap* map, const char* key, int* error) = 0; 1805 | virtual const double *__stdcall propGetFloatArray(const AVSMap* map, const char* key, int* error) = 0; 1806 | virtual int __stdcall propSetIntArray(AVSMap* map, const char* key, const int64_t* i, int size) = 0; 1807 | virtual int __stdcall propSetFloatArray(AVSMap* map, const char* key, const double* d, int size) = 0; 1808 | 1809 | virtual AVSMap* __stdcall createMap() = 0; 1810 | virtual void __stdcall freeMap(AVSMap* map) = 0; 1811 | virtual void __stdcall clearMap(AVSMap* map) = 0; 1812 | 1813 | // Support functions 1814 | virtual void* __stdcall Allocate(size_t nBytes, size_t alignment, AvsAllocType type) = 0; 1815 | virtual void __stdcall Free(void* ptr) = 0; 1816 | 1817 | virtual char* __stdcall SaveString(const char* s, int length = -1) = 0; 1818 | virtual char* __stdcall SaveString(const char* s, int length, bool escape) = 0; 1819 | virtual char* Sprintf(const char* fmt, ...) = 0; 1820 | virtual char* __stdcall VSprintf(const char* fmt, va_list val) = 0; 1821 | 1822 | __declspec(noreturn) virtual void ThrowError(const char* fmt, ...) = 0; 1823 | 1824 | virtual void __stdcall ApplyMessage(PVideoFrame* frame, const VideoInfo& vi, const char* message, int size, 1825 | int textcolor, int halocolor, int bgcolor) = 0; 1826 | 1827 | // Setting 1828 | virtual int __stdcall SetMemoryMax(int mem) = 0; 1829 | virtual int __stdcall SetMemoryMax(AvsDeviceType type, int index, int mem) = 0; 1830 | 1831 | virtual bool __stdcall PlanarChromaAlignment(IScriptEnvironment::PlanarChromaAlignmentMode key) = 0; 1832 | virtual int __stdcall SetWorkingDir(const char * newdir) = 0; 1833 | virtual void* __stdcall ManageCache(int key, void* data) = 0; 1834 | 1835 | virtual void __stdcall AtExit(ShutdownFunc function, void* user_data) = 0; 1836 | virtual void __stdcall CheckVersion(int version = AVISYNTH_INTERFACE_VERSION) = 0; 1837 | 1838 | // Threading 1839 | virtual void __stdcall SetFilterMTMode(const char* filter, MtMode mode, bool force) = 0; 1840 | virtual IJobCompletion* __stdcall NewCompletion(size_t capacity) = 0; 1841 | virtual void __stdcall ParallelJob(ThreadWorkerFuncPtr jobFunc, void* jobData, IJobCompletion* completion) = 0; 1842 | 1843 | // CUDA Support 1844 | virtual PDevice __stdcall GetDevice(AvsDeviceType dev_type, int dev_index) const = 0; 1845 | virtual PDevice __stdcall GetDevice() const = 0; // get current device 1846 | virtual AvsDeviceType __stdcall GetDeviceType() const = 0; 1847 | virtual int __stdcall GetDeviceId() const = 0; 1848 | virtual int __stdcall GetDeviceIndex() const = 0; 1849 | virtual void* __stdcall GetDeviceStream() const = 0; 1850 | virtual void __stdcall DeviceAddCallback(void(*cb)(void*), void* user_data) = 0; 1851 | 1852 | virtual PVideoFrame __stdcall GetFrame(PClip c, int n, const PDevice& device) = 0; 1853 | 1854 | }; 1855 | 1856 | // support interface conversion 1857 | struct PNeoEnv { 1858 | INeoEnv* p; 1859 | PNeoEnv() : p() { } 1860 | PNeoEnv(IScriptEnvironment* env) 1861 | #ifdef BUILDING_AVSCORE 1862 | ; 1863 | #else 1864 | : p(!AVS_linkage || offsetof(AVS_Linkage, GetNeoEnv) >= AVS_linkage->Size ? 0 : AVS_linkage->GetNeoEnv(env)) { } 1865 | #endif 1866 | 1867 | int operator!() const { return !p; } 1868 | operator void*() const { return p; } 1869 | INeoEnv* operator->() const { return p; } 1870 | #ifdef BUILDING_AVSCORE 1871 | inline operator IScriptEnvironment2*(); 1872 | inline operator IScriptEnvironment_Avs25* (); 1873 | #else 1874 | operator IScriptEnvironment2*() { return p->GetEnv2(); } 1875 | operator IScriptEnvironment_Avs25* () { return p->GetEnv25(); } 1876 | #endif 1877 | }; 1878 | 1879 | 1880 | // avisynth.dll exports this; it's a way to use it as a library, without 1881 | // writing an AVS script or without going through AVIFile. 1882 | AVSC_API(IScriptEnvironment*, CreateScriptEnvironment)(int version = AVISYNTH_INTERFACE_VERSION); 1883 | 1884 | 1885 | // These are some global variables you can set in your script to change AviSynth's behavior. 1886 | #define VARNAME_AllowFloatAudio "OPT_AllowFloatAudio" // Allow WAVE_FORMAT_IEEE_FLOAT audio output 1887 | #define VARNAME_VDubPlanarHack "OPT_VDubPlanarHack" // Hack YV16 and YV24 chroma plane order for old VDub's 1888 | #define VARNAME_AVIPadScanlines "OPT_AVIPadScanlines" // Have scanlines mod4 padded in all pixel formats 1889 | #define VARNAME_UseWaveExtensible "OPT_UseWaveExtensible" // Use WAVEFORMATEXTENSIBLE when describing audio to Windows 1890 | #define VARNAME_dwChannelMask "OPT_dwChannelMask" // Integer audio channel mask. See description of WAVEFORMATEXTENSIBLE for more info. 1891 | #define VARNAME_Enable_V210 "OPT_Enable_V210" // AVS+ use V210 instead of P210 (VfW) 1892 | #define VARNAME_Enable_Y3_10_10 "OPT_Enable_Y3_10_10" // AVS+ use Y3[10][10] instead of P210 (VfW) 1893 | #define VARNAME_Enable_Y3_10_16 "OPT_Enable_Y3_10_16" // AVS+ use Y3[10][16] instead of P216 (VfW) 1894 | #define VARNAME_Enable_b64a "OPT_Enable_b64a" // AVS+ use b64a instead of BRA[64] (VfW) 1895 | #define VARNAME_Enable_PlanarToPackedRGB "OPT_Enable_PlanarToPackedRGB" // AVS+ convert Planar RGB to packed RGB (VfW) 1896 | 1897 | // C exports 1898 | #include "avs/capi.h" 1899 | AVSC_API(IScriptEnvironment2*, CreateScriptEnvironment2)(int version = AVISYNTH_INTERFACE_VERSION); 1900 | 1901 | #ifndef BUILDING_AVSCORE 1902 | #undef AVS_UNUSED 1903 | #endif 1904 | 1905 | #pragma pack(pop) 1906 | 1907 | #endif //__AVISYNTH_8_H__ 1908 | --------------------------------------------------------------------------------