Log in

View Full Version : Unable to compile an AviSynth C++ DLL


Forensic
11th November 2013, 02:42
I recently began working with Orwell Dev-C++ on my Win-7 32-bit PC to create DLLs for use with AviSynth 2.58. I saved avisynth.h (http://avisynth.nl/images/Avisynth.h-2.5.8.avs) in (MingGW32\include). However, compiling causes
[error] can't create precompiled header c:\program files\dev-cpp\mingw32\include\avisynth.exe: Permissions denied
I tried saving it in (MinGW32\lib\gcc\mingw32\4.7.2\include), but the result was the same. Any suggestions?

Jeroi
11th November 2013, 05:52
I recently began working with Orwell Dev-C++ on my Win-7 32-bit PC to create DLLs for use with AviSynth 2.58. I saved avisynth.h (http://avisynth.nl/images/Avisynth.h-2.5.8.avs) in (MingGW32\include). However, compiling causes
[error] can't create precompiled header c:\program files\dev-cpp\mingw32\include\avisynth.exe: Permissions denied
I tried saving it in (MinGW32\lib\gcc\mingw32\4.7.2\include), but the result was the same. Any suggestions?

Just create your folder anywhere on your system. It does not need to be at there where you placed it. Just remember when you compile with make, remember to check $PATH variable so that /usr/lib is there and use "export PATH=yourpath:another:another" to include all the necessary folders. Aivisynth.h and avisynthdll.h needs winapi32 libraries so that's why you need to check the path environment variable. How ever isin't avisynth .NET?

Edit: I strongly suggest of downloading QT5.1 SDK and QT Creator. There is simple create DLL method that implements QT dll structure and shows your first DLL function right away including header class to export your functions. Whats best is, that you are making Cross platform version of your dll's.

StainlessS
11th November 2013, 06:00
Avisynth.h is part of your project and should be in same directory as your source files,
included with

#include "Avisynth.h"

rather than

#include <Avisynth.h>

which includes from the compiler include paths.
You might find more assistance if you post in one of the Avisynth Developer forum sticky threads, also at least until
more comfortable with C/CPP, maybe try out MS Express editions or one of the other compilers mentioned in the
stickies threads.

EDIT:
How ever isin't avisynth .NET?

No.

EDIT: And start with the Simple Sample stuff in Avisynth Developer forum SDK sticky thread.

Forensic
11th November 2013, 09:11
First off...thank you. My goal is to create a GUI for AVIsynth and VapourSynth. Think of it as AVSpmod on steroids, but specifically targeting the world of video forensics. I have a strong familiarity with Javascript and AVIsynth scripts, but all this CPP C# stuff is new to me (and rather reminiscent of circa 1970's Cobol)?

Jeroi, I have no loyalty to Orwell C++, and will gladly download Qt 5.1.1 for Windows 32-bit. Do you recommend that I go with VS 2012 -or- MinGW 4.8, OpenGL?
I already have Aivisynth.h from the link in my original post. Where do I get avisynthdll.h plus the winapi32 libraries you mentioned?

Jeroi
11th November 2013, 13:14
First off...thank you. My goal is to create a GUI for AVIsynth and VapourSynth. Think of it as AVSpmod on steroids, but specifically targeting the world of video forensics. I have a strong familiarity with Javascript and AVIsynth scripts, but all this CPP C# stuff is new to me (and rather reminiscent of circa 1970's Cobol)?

Jeroi, I have no loyalty to Orwell C++, and will gladly download Qt 5.1.1 for Windows 32-bit. Do you recommend that I go with VS 2012 -or- MinGW 4.8, OpenGL?
I already have Aivisynth.h from the link in my original post. Where do I get avisynthdll.h plus the winapi32 libraries you mentioned?

Mingw+QT5.1+qt creator is free opensource toolchain. With mingw you can use GIT also or SVN to track your progress.

When you install Mingw to some harddisk root, then QT will ask you where the Mingw is located and then add your combilers to QT configs. So you can use mingw to combile your code in QT Creator and debug aswell.

StainlessS
11th November 2013, 17:51
Just for your info Forensic, the Avisynth.h header you linked, is a version 3 header for 2.5 plugins, you might also
want version 5 for v2.6 plugins, latest of both can be found in source of any of the 25&26 plugins on MediaFire
in my sig (eg RT_Stats).
Check in SDK stickies to see if other people have successfully used MingW for plugin development, once familiar with the
language, you can switch to whatever compiler you want provided it links nice with MS dll's and CPP binary
compatible.

StainlessS
12th November 2013, 13:03
It looks to me as though you cannot compile an autoloading CPP plugin using MingW, only manual loading C plugins and so you would need the Kevin Atkinson
Avisynth_c.h header, think it was updated not so long ago, but dont know where to get update.
See also Compiling Avisynth plugins and Avisynth Plugin development in C on Avisynth.nl main page here: http://www.avisynth.nl/index.php/Main_Page#Development

the Development in C link actually takes you here: http://avisynthnew.wikinet.org/wiki/Avisynth_Plugin_Development_in_C, looks to be written by Jmac968 who was not so very long ago, an non CPP programmer.

and the links here: http://forum.doom9.org/showthread.php?p=1651935#post1651935

Jeroi
12th November 2013, 15:02
It looks to me as though you cannot compile an autoloading CPP plugin using MingW, only manual loading C plugins and so you would need the Kevin Atkinson
Avisynth_c.h header, think it was updated not so long ago, but dont know where to get update.
See also Compiling Avisynth plugins and Avisynth Plugin development in C on Avisynth.nl main page here: http://www.avisynth.nl/index.php/Main_Page#Development

the Development in C link actually takes you here: http://avisynthnew.wikinet.org/wiki/Avisynth_Plugin_Development_in_C, looks to be written by Jmac968 who was not so very long ago, an non C programmer.

and the links here: http://forum.doom9.org/showthread.php?p=1651935#post1651935

I have almoust already ported avisynth.h to QT in my MeXgui project. I need to rewrite com controlls in it to be able to combile and some windows objects related code still to debug. Once this is done, Avisynth.H will support crossplatform native plugin development with QT. I will rename it to Avisythqt.H or QT_Avisynth.H or similar.

So soon there is valid avisynth.H for c++ QT. And it's exiting thingy because QT Creator can make DLL projects with couble clicks and then using qt_avisynth.h inside the dll you can have your nasty object oriented programming and generate nice plugins for free.

The reason why g++ fails with avisynth.H is that it uses object.H which is m$ file. Also it uses some windows io.H headers to be able to talk with Windows. MinGW misses I think object.H atleast in winapi support and other activeX related things.

StainlessS
12th November 2013, 16:25
So soon there is valid avisynth.H for c++ QT. And it's exiting thingy because QT Creator can make DLL projects with couble clicks and then using qt_avisynth.h inside the dll you can have your nasty object oriented programming and generate nice plugins for free.

Sound good to me. Good luck with your new project. :)

EDIT: Good luck to both of you.

Forensic
14th November 2013, 23:41
Handaimoah: my question is, from your expertise, should the MSVC++ version (Microsoft Visual Studio Express 2012 for Windows Desktop) along with (Qt 5.1.1 for Windows 32-bit VS 2012) be compatible with avisynth.h (2.5 v3) {http://avisynth.nl/images/Avisynth.h-2.5.8.avs} for the development of DLLs? Is there anything else I will need?

Jeroi
15th November 2013, 00:03
Handaimoah: my question is, from your expertise, should the MSVC++ version (Microsoft Visual Studio Express 2012 for Windows Desktop) along with (Qt 5.1.1 for Windows 32-bit VS 2012) be compatible with avisynth.h (2.5 v3) {http://avisynth.nl/images/Avisynth.h-2.5.8.avs} for the development of DLLs? Is there anything else I will need?

Afaik you don't need QT for avisynth plugins, since you are handling video or audio so it is mathematical calculation basically so no need for QT which is GUI development SDK to provide crostool support natively to GUI programs.

Forensic
17th November 2013, 01:57
I installed minGW32 and successfully compiled a static CPP build through TextPad (http://youtu.be/65aTci7dh04), but it lacks any debugging beyond a useless "error code 1" and only creates an EXE. I found ample Avisynth DLL compiling instructions, but those either require purchasing the Professional version of VC++, using software that is no longer available, or using older software that is incompatible with my Windows-7 32-bit PC. I believe it is possible to use QT5.1 (for ease of creating/debugging CPP code) with my minGW32 to create a static Avisynth 2.58 compliant CPP DLL, but I can't figure how.

I have the Avisynth.h (2.58 ver 3) file. What I can't figure out are the actual steps to convert a known valid Avisynth 2.58 CPP script into a static build Avisynth 2.58 compliant DLL. I am seeking the compiling instructions, including where to place the Avisynth.h file and any other Avisynth files required for a successful build. If QT and/or minGW32 is an invalid development tool, then I will use whatever you know will work. Once I have successfully compiled one DLL, I am ready to do this for many. Can anyone help?

Groucho2004
17th November 2013, 02:20
What I can't figure out are the actual steps to convert a known valid Avisynth 2.58 CPP script into a static build Avisynth 2.58 compliant DLL.
You have mentioned this before but it still evades me what you mean by "cpp script". Could you post the content of such a file?

Groucho2004
17th November 2013, 02:39
I found ample Avisynth DLL compiling instructions, but those either require purchasing the Professional version of VC++, using software that is no longer available, or using older software that is incompatible with my Windows-7 32-bit PC.
Here (http://vecchio56.free.fr/VCToolkitSetup.exe) is a link for the free MS VC7.1 compiler which should work on your system.
The Platform SDK that goes with it should be this one (http://www.microsoft.com/en-us/download/details.aspx?id=12261).
You should have no problems building Avisynth plugins with this environment.

Edit: neuron2 beat me to it...

Edit1: Here (http://wiki.codeblocks.org/index.php?title=Integrating_Microsoft_Visual_Toolkit_2003_with_Code::Blocks_IDE) is a link to Code::Blocks and how to integrate the VC7.1 compiler into their IDE. I heard some good things about that IDE, give it a go.

Forensic
17th November 2013, 03:43
Last week I installed "Microsoft Visual Studio 2012 Express" and, based on today's advice, I installed "Microsoft Visual C++ Toolkit 2003" and "Microsoft Platform SDK for Windows Server 2003 R2". I have no problem writing a hello world script and am getting the initial hang of CPP structure. I have compiled scripts into EXEs using the minGW32-TextPad setup as noted previously.
I am sorry to bother you, but I am stopped by the hurdle of how to create an Avisynth 2.58 compliant DLL, regardless of its simplicity. I am not asking for help on writing a script, just the configuration steps and additional files (e.g. other "h" files) needed to get to the finish line. Any advice?
To address neuron2's question, I am building DLLs now with the eventual goal of writing a complete GUI application.

TheFluff
17th November 2013, 06:52
This forum sure has been full of people getting in way over their heads lately. Jeroi has always been beyond all help, but for you others, I'd like to mention the following about Avisynth plugin development:

The Avisynth API is a C++ API, and C++ API's are a terrible idea because different compilers have different ideas about what the ABI should look like. In practice, this means that if you want things to work 100% as expected, YOU MUST COMPILE YOUR PLUGIN WITH THE SAME COMPILER THAT WAS USED TO COMPILE AVISYNTH. That's MSVC 6.0 for official builds. Later versions of MSVC will kinda sorta work, as will ICL, but there are caveats (for example, you must never allow any C++ exceptions to escape your plugin ever - see this post by ultim for details (http://forum.doom9.org/showthread.php?p=1647262#post1647262) - and you must always make sure memory allocated by Avisynth is freed by Avisynth itself and not by your plugin). MinGW most definitely doesn't work, and that's why the Avisynth C API exists: if you want a portable API, you want a C API. C++ API's are more or less by definition unportable, and Jeroi is (obviously) delusional.

Avisynth itself (the official branch) relies on a ton of Windows-specific and MSVC-specific things and you shouldn't even bother trying to compile with anything else. Even if you rewrote or removed all the unportable parts (like Avxsynth) compiling it with a different compiler would make your Avisynth incompatible with existing plugins (except possibly the ones using the C interface, heh).

By the way, it should be obvious, but just in case: if your intention is not to write a plugin but rather to use the Avisynth API from a standalone application, all of the above still applies. Especially the exception handling part.

Forensic
17th November 2013, 09:02
First off, thank you for all the guidance, advice and links. Sorry about calling CPP code a script (force of habit). I promise to move slowly and heed the wisdom of others. C# and C++ are new to me, and my immediate goal is a greater understanding of its structure and syntax, in addition to the coding aspects unique to Avisynth and VapourSynth. First task... researching the cause of my two errors with the sample CPP code. I am sure that I am making a common newbie mistake:
warning C4627: '#include "avisynth.h"': skipped when looking for precompiled header use
error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

Groucho2004
17th November 2013, 11:36
The Avisynth API is a C++ API, and C++ API's are a terrible idea because different compilers have different ideas about what the ABI should look like. In practice, this means that if you want things to work 100% as expected, YOU MUST COMPILE YOUR PLUGIN WITH THE SAME COMPILER THAT WAS USED TO COMPILE AVISYNTH. That's MSVC 6.0 for official builds. Later versions of MSVC will kinda sorta work, as will ICL, but there are caveats (for example, you must never allow any C++ exceptions to escape your plugin ever - see this post by ultim for details (http://forum.doom9.org/showthread.php?p=1647262#post1647262) - and you must always make sure memory allocated by Avisynth is freed by Avisynth itself and not by your plugin).
All true but I'd venture a guess that less than 20% of existing plugins are built with VC6 since people just don't have it - just some dinosaurs like me.
BTW, I'm using VC6 with ICL10.1 which is the last ICL version that is compatible with VC6.

TurboPascal7
17th November 2013, 11:56
BTW, I'm using VC6 with ICL10.1 which is the last ICL version that is compatible with VC6.
Omg, why?
And here I considered you a possible avs+ contributor.

Groucho2004
17th November 2013, 12:04
Omg, why?
And here I considered you a possible avs+ contributor.
I also have various other compilers, like VC10 which I use for most other purposes than things related to the "official" Avisynth.

StainlessS
17th November 2013, 15:02
error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

In VC6 New Project, I generally choose Win32 Dynamic-Link Library, with Location
set to my Projects directory and Win32 box ticked. Give it a Project name eg 'Sin'.

I next step, I always select 'An Empty DLL Project' (avoids that stdafx stuff).

In FilesView
Add avisynth.h (and any other of your self made headers) to the Header Files
Add Sin.cpp to the Source Files.

Sin.CPP (From SDK NON-ClipSample)

#include <windows.h> // from compiler/SDK include dir
#include <math.h> // from compiler/SDK include dir
#include "avisynth.h" // In your project dir

AVSValue Sin(AVSValue args, void* user_data, IScriptEnvironment* env) {
return sin(args[0].AsFloat());
}

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("sin", "f", Sin, 0);
return "sin";
}


About as simple as it gets.

By The Way, this is how I have my Menu/Tools/Options/Directories set for VS6 + ToolKit 2003 + SDK:

Executable Files:::
C:\Program Files\Microsoft SDK\bin
C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin
C:\Program Files\Microsoft Visual Studio\VC98\BIN
C:\Program Files\Microsoft SDK\bin\winnt
C:\Program Files\Microsoft Visual Studio\COMMON\TOOLS
C:\Program Files\Microsoft Visual Studio\COMMON\MSDev98\Bin
C:\Program Files\Microsoft Visual Studio\COMMON\TOOLS\WINNT
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\Program Files\Intel\DMIX
C:\WINDOWS\system32\WindowsPowerShell\v1.0
C:\Program Files\Support Tools

Include Files:::
C:\Program Files\Microsoft SDK\include
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE

Library Files:::
C:\Program Files\Microsoft SDK\lib
C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib
C:\Program Files\Microsoft Visual Studio\VC98\LIB
C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB

Only first 3 files of each section really relevent, I put VC98 entries above Toolkit 2003 normally
(and for debugging as ToolKit 2003 has no debugging), and for final, switch TK2003 above VC98.

Hopefully not too dissimilar to VC2012.

PS, you might find the Avisynth Compiled Help With SDK (CHM) File for v2.6 useful (MediaFire in sig), stick it on a hot-Key.

Gavino
17th November 2013, 16:51
Avisynth.h is part of your project and should be in same directory as your source files,
included with

#include "Avisynth.h"

rather than

#include <Avisynth.h>

which includes from the compiler include paths.
That's not necessary.
Rather than have a copy of avisynth.h in every project source file directory, I prefer just to add the containing folder (eg C:\Program Files\AviSynth 2.5\FilterSDK\include) to the list of include directories for the project. I then use #include <avisynth.h>.

StainlessS
17th November 2013, 18:00
Arh but, I frequently use Avisynth.h, Avisynth25.h, Avisynth26.h, and like them when I can get at them easily (and the correct ones) when copying source files for zip.

Forensic
20th November 2013, 06:07
In VS12, I went to (NEW - Visual C++ Win32 Project - DLL Empty project) and got:

http://forensicprotection.com/Compile/Compile.jpg

I also tried to get to the finish line with "C:\Program Files\Microsoft Visual Studio\Common\IDE\IDE98\MSE.EXE" but that behaves as just a text editor.

I also have "Visual C++ Toolkit 2003 Command Prompt" but have not yet figured how to use that, if that is the correct solution.

jackoneill
20th November 2013, 09:46
#include <math.h>

JEEB
20th November 2013, 09:56
C/C++ basics, you include and link (if needed) the things you are using from the standard libraries.

Some reference (http://www.cplusplus.com/reference/cmath/sin/).

Basically include cmath or math.h (the "C++ way" is the first, and the second is the C way -- both should lead to the same result), and the compiler should stop complaining. If the linker complains about not finding the actual implementation, you link the according standard library library.

Also make sure you actually need that windows.h header, don't just include it blindly :P .

Gavino
20th November 2013, 11:02
C/C++ basics, you include and link (if needed) the things you are using from the standard libraries.

Some reference (http://www.cplusplus.com/reference/cmath/sin/).
Also, if you need to use constants like pi, e, etc, in your code, add the following line before including cmath or math.h:
#define _USE_MATH_DEFINES
See http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx.

In my view, this is better than defining them yourself like JEEB's reference does.
For one thing, it saves you looking up the exact value and possibly mistyping the numbers.

JEEB
20th November 2013, 11:31
Yes, naturally. My intention was to just bring to his knowledge that he should look into how the language and its standard library work in general.

StainlessS
20th November 2013, 18:07
Sorry Forensic, my fault, should have included the "#include <math.h>" line. :(

Forensic
20th November 2013, 18:08
#define _USE_MATH_DEFINES
#include <math.h>
Adding those two lines eliminated the errors and gave me my first successful AviSynth DLL (now I just have to ask StainlessS how I test his mini-creation). Recompiling other people's valid source code provides a means for me to test how modifications affect the results. That is how I expedited my understanding of AviSynth scripting. I am extremely appreciative of everyone's assistance, and willingness to do so. I realize that my C++ floundering can border on being both comical and a bit pathetic. There are a lot of structural and syntax rules to learn about C++, especially as they relate to building Avisynth 2.58 compliant DLLs. Made tougher by the fact that the last "real" programming languages I used were Cobol, integer basic and 6502 assembly (all from the 1970s). I am incredibly appreciative of everyone's feedback and apologize if my Deer in the headlights comments ever imply anything else. My ONLY goal at this point, is to create useful Avisynth compliant DLLs so I can contribute to my forensic peers and the Doom9 community.

Gavino
20th November 2013, 18:11
Yes, naturally. My intention was to just bring to his knowledge that he should look into how the language and its standard library work in general.
I realise that, I was just adding more information to supplement your already helpful post.

However, I'm not so sure about this part:
Also make sure you actually need that windows.h header, don't just include it blindly :P .
In my experience, windows.h is always needed before including avisynth.h. Otherwise, you get loads of errors from other windows-related header files that would probably be incomprehensible to a newbie.

StainlessS
20th November 2013, 18:33
Nothing wrong with trying out the simplest test dll just to see if the setup works, indeed quite logical.


colorbars
q=PI/4.0
s= Sin(q)
Subtitle("Sin(" + String(q) + ")" + " = " + String(s))
return last


Now to get to the filter type dll's. :) (Dont forget to remove dll from plugins)

Forensic
20th November 2013, 18:44
StainlessS, thank you. Now I know that I can successfully compile something (anything) that works!!! Yea. Mission #1 done. Now that my compiler works, back to filters.

Groucho2004
20th November 2013, 19:30
Now that my compiler works, back to filters.
Next exercise (:p):
Make a DLL out of this code and figure out what it does:
#include <windows.h>
#include "avisynth.h"

class Invert : public GenericVideoFilter
{
public:
Invert(PClip _child) : GenericVideoFilter(_child) {}
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
private:
const BYTE* srcpY;
const BYTE* srcpU;
const BYTE* srcpV;
};

AVSValue __cdecl Create_Invert(AVSValue args, void* user_data, IScriptEnvironment* env)
{
return new Invert(args[0].AsClip());
}

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env)
{
env->AddFunction("Invert", "c", Create_Invert, 0);
return "Invert plugin";
}

PVideoFrame __stdcall Invert::GetFrame(int n, IScriptEnvironment* env)
{
PVideoFrame src = child->GetFrame(n, env);
PVideoFrame dst = env->NewVideoFrame(vi);

srcpY = src->GetReadPtr(PLANAR_Y);
srcpU = src->GetReadPtr(PLANAR_U);
srcpV = src->GetReadPtr(PLANAR_V);

BYTE* dstpY = dst->GetWritePtr(PLANAR_Y);
BYTE* dstpU = dst->GetWritePtr(PLANAR_U);
BYTE* dstpV = dst->GetWritePtr(PLANAR_V);

const int src_pitchY = src->GetPitch(PLANAR_Y);
const int src_pitchUV = src->GetPitch(PLANAR_V);
const int dst_pitchY = dst->GetPitch(PLANAR_Y);
const int dst_pitchUV = dst->GetPitch(PLANAR_U);

const int row_sizeY = dst->GetRowSize(PLANAR_Y);
const int row_sizeUV = dst->GetRowSize(PLANAR_U);

const int heightY = dst->GetHeight(PLANAR_Y);
const int heightUV = dst->GetHeight(PLANAR_U);

int y, x;

for (y = 0; y < heightY; y++)
{
for (int x = 0; x < row_sizeY; x++)
dstpY[x] = srcpY[x] ^ 0xFF;

srcpY += src_pitchY;
dstpY += dst_pitchY;
}

for (y = 0; y < heightUV; y++)
{
for (int x = 0; x < row_sizeUV; x++)
{
dstpU[x] = srcpU[x] ^ 0xFF;
dstpV[x] = srcpV[x] ^ 0xFF;
}

srcpU += src_pitchUV;
dstpU += dst_pitchUV;
srcpV += src_pitchUV;
dstpV += dst_pitchUV;
}

return dst;
}

Gavino
20th November 2013, 19:59
Make a DLL out of this code and figure out what it does
For bonus points, explain why it is not thread-safe, and how that can be fixed.
Hint:
class Invert : public GenericVideoFilter
{
...
const BYTE* srcpY;
const BYTE* srcpU;
const BYTE* srcpV;
};

Forensic
20th November 2013, 20:55
Groucho2004. That is so awesome that you are doing this for me. Hopefully, all of the newbies will benefit from this too. Compiling and loading the DLL was easy enough and my best guess of your code is that it shifts the U&V pixel values in a linear fashion with each successive frame. The part stumping me is the function call. Reading your code, I thought the call (using colorbars for the test) was colorbars.PVideoFrame or colorbars.Invert
The first one fails to be recognized and the second is an internal call. So I admit my stupidity....what is the function call?

StainlessS
20th November 2013, 21:34
Argument is clip only, source clip Planar, Colorbars().ConvertToYV12().Invert(),
dont forget to copy dll to plugins, else will use built-in Invert().
Remove dll afterwards.

Below tells avisynth about the plugin name and args.

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env)
{
env->AddFunction("Invert", "c", Create_Invert, 0);
return "Invert plugin";
}


This is (TwoFiveInvert) sample from SDK. http://avisynth.nl/index.php/Filter_SDK
also in Avisynth 2.6 + SDK compressed helpfile as previously posted (MediaFire in sig).
EDIT: Not TwoFiveInvert, but very similar.

EDIT: This is the bit that does invert (on Y)

dstpY[x] = srcpY[x] ^ 0xFF;


the '^' is XOR, XOR with $FF makes eg 0->FF and FF->0. (Copying from source, XOR, to Dest)

To call another built-in or external function (you need to know it exists) see Invoke. http://avisynth.nl/index.php/Cplusplus_API
(Most filters do the hard work themselves and do not call built-in/external filters)

Forensic
20th November 2013, 22:10
I did not realize the DLL worked because its functionality was indistinguishable fromo the internal "Invert" function. So...I recompiled it after changing all instances of "Invert" to "InvertX", just to be sure, and everything worked. Best of all, everything is being done in VC++ 2012 Express. I will now manipulate this code, and other plug-in source codes, along with reading two very large C++ books. As for Gavino's bonus question on thread-safe coding; my best guess is that the noted constants are being defined as public variable that potentially conflict with other functions wanting to load, or overload, the same variable names. But that is just my instinctual guess...not from understanding C++.

StainlessS
20th November 2013, 22:12
Methinks that the Gavino Bonus Points were aimed at Grouchy. :)

Groucho2004
20th November 2013, 22:29
For bonus points, explain why it is not thread-safe, and how that can be fixed.
Hint:
class Invert : public GenericVideoFilter
{
...
const BYTE* srcpY;
const BYTE* srcpU;
const BYTE* srcpV;
};

Damn, didn't realize that was still there. I was playing around with this a long time ago. I should really look at the code before posting...
Yes, these 3 const BYTE* should be local in ::GetFrame() just as the "BYTE* dstp" vars.

Gavino
20th November 2013, 22:31
Methinks that the Gavino Bonus Points were aimed at Grouchy. :)
Not really, I just assumed Groucho had copied the example from somewhere else.

The problem with the code is that those variables should just be local variables inside GetFrame, especially since nothing else uses them. Putting them at the class level means that two threads cannot call GetFrame at the same time (on a single instance of the filter) without interfering with each other.

StainlessS
21st November 2013, 02:16
Apologies to the Grouchy man, :) Gavino, you seemed to me to be a Sort of teacher,
no longer. Why would you expect a newbie to consider multi threading, I dont understand that
and I consider myself not a total newbie.
Gavino, methinks you were not at your best there.
Appologies to the Grouchy man (He He).
Bit pissed at the moment, but, will, (god wiilling, [if there is such an object])
arise, again.

Groucho2004
21st November 2013, 02:26
Bit pissed at the moment
That's obvious. :D

For tomorrow when you're sober: How to develop thread safe filters (http://avisynth.nl/index.php/MT#How_to_development_threadsafe_filters)

Gavino
21st November 2013, 11:45
Why would you expect a newbie to consider multi threading, I dont understand that
and I consider myself not a total newbie.
I wouldn't expect a newbie to be aware of the issues, but was flagging it for his attention at some later time.

At a simpler level, there was also the point that variables that were only required inside one function, and not needed to persist, were declared at the class level, which is bad practice regardless of the multithreading issue.