Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
17th November 2013, 15:02 | #21 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
|
Quote:
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) Code:
#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"; } 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.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 20th November 2013 at 18:09. |
|
17th November 2013, 16:51 | #22 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,433
|
Quote:
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>. |
|
17th November 2013, 18:00 | #23 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
|
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.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
20th November 2013, 06:07 | #24 | Link |
Registered User
Join Date: Apr 2008
Location: California, USA
Posts: 127
|
I am struggling to solve this myself....but...
In VS12, I went to (NEW - Visual C++ Win32 Project - DLL Empty project) and got:
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. |
20th November 2013, 09:56 | #26 | Link |
もこたんインしたお!
Join Date: Jan 2008
Location: Finland / Japan
Posts: 512
|
C/C++ basics, you include and link (if needed) the things you are using from the standard libraries.
Some reference. 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 .
__________________
[I'm human, no debug]
|
20th November 2013, 11:02 | #27 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,433
|
Quote:
Code:
#define _USE_MATH_DEFINES 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. |
|
20th November 2013, 18:07 | #29 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
|
Sorry Forensic, my fault, should have included the "#include <math.h>" line.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
20th November 2013, 18:08 | #30 | Link |
Registered User
Join Date: Apr 2008
Location: California, USA
Posts: 127
|
#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. |
20th November 2013, 18:11 | #31 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,433
|
Quote:
However, I'm not so sure about this part: 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. |
|
20th November 2013, 18:33 | #32 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
|
Nothing wrong with trying out the simplest test dll just to see if the setup works, indeed quite logical.
Code:
colorbars q=PI/4.0 s= Sin(q) Subtitle("Sin(" + String(q) + ")" + " = " + String(s)) return last
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 20th November 2013 at 18:49. |
20th November 2013, 19:30 | #34 | Link |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
Next exercise ():
Make a DLL out of this code and figure out what it does: Code:
#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; } |
20th November 2013, 19:59 | #35 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,433
|
For bonus points, explain why it is not thread-safe, and how that can be fixed.
Hint: Code:
class Invert : public GenericVideoFilter { ... const BYTE* srcpY; const BYTE* srcpU; const BYTE* srcpV; }; |
20th November 2013, 20:55 | #36 | Link |
Registered User
Join Date: Apr 2008
Location: California, USA
Posts: 127
|
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? |
20th November 2013, 21:34 | #37 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
|
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. Code:
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) { env->AddFunction("Invert", "c", Create_Invert, 0); return "Invert plugin"; } 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) Code:
dstpY[x] = srcpY[x] ^ 0xFF; 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)
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 20th November 2013 at 21:55. |
20th November 2013, 22:10 | #38 | Link |
Registered User
Join Date: Apr 2008
Location: California, USA
Posts: 127
|
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++.
|
20th November 2013, 22:12 | #39 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,018
|
Methinks that the Gavino Bonus Points were aimed at Grouchy.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
20th November 2013, 22:29 | #40 | Link | |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
Quote:
Yes, these 3 const BYTE* should be local in ::GetFrame() just as the "BYTE* dstp" vars. |
|
Tags |
avisynth, c++, compile, dll |
Thread Tools | Search this Thread |
Display Modes | |
|
|