View Full Version : file read for use in plugin
PeaceAnt
19th November 2008, 00:30
hi,
i'm trying to write a plugin similar to gicocu, so i need an example how to read an array from file in plugin. i couldn't find source code of gicocu or something similar.
i'll be very thankful for your help.
pozdrawiam (greetings)
Guest
19th November 2008, 00:32
Just use standard file IO, i.e., open the file, read it, close it. What's the big deal?
IanB
19th November 2008, 07:01
Filter::Filter(...) is the constructor and is run when you "new" an instance of the filter. Do one time filter initialisation code here. i.e. Open any global data files, read their contents, build any static tables required and close them, or open a file for per frame i/o (save the handle as a class variable).
Filter::Create(..., env) is a static method registered when you called env->AddFunction(...) and is called by the parser as a script is being compiled to resolve a statement referencing your filter. Instantiate ("new") your filter object(s) here.
Filter::GetFrame(n, env) is the per frame rendering code, called each time a frame is required by the next filter in the chain. Do any per frame reads and/or writes here. See also GetAudio() for any audio processing requirements.
Filter::~Filter() is the destructor and is run when the compiled filter graph is being deleted. Close any per frame files opened in the constructor here. "delete" any static tables you may have "new'd".
stickboy
19th November 2008, 07:19
You could look at the source code to my RemapFrames plug-in (http://www.avisynth.org/stickboy/).
PeaceAnt
19th November 2008, 11:27
thanks for reply.
unfortunately i'm afraid it's to complicated for me at this moment. in fact i learn c++ just to write a few plugins for avisynth and i wrote 1 so far (compound arithmetic with many blend modes - i'm still not ready to show you that, but i will surely) and i need exactly one thing:
load 2D lookup table (a raw bitmap 256x256x8bit exactly) from file or just create it once for use it in every frame.
i think we could use a little modified simplesample code by Simon to make an example:
#include "windows.h"
#include "avisynth.h"
class SimpleSample : public GenericVideoFilter {
PClip WindowVideo;
int SquareSize;
int param1;
int param2;
//this params for further use
public:
SimpleSample(PClip _child, PClip _WindowVideo, int _SquareSize, int _param1, int _param2, IScriptEnvironment* env);
~SimpleSample();
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};
SimpleSample::SimpleSample(PClip _child, PClip _WindowVideo, int _SquareSize, int _param1, int _param2, IScriptEnvironment* env) :
GenericVideoFilter(_child), WindowVideo(_WindowVideo), SquareSize(_SquareSize), param1(_param1), param2(_param2){
} //<--------- OPEN AND READ HERE?------------------------
SimpleSample::~SimpleSample() {
}
PVideoFrame __stdcall SimpleSample::GetFrame(int n, IScriptEnvironment* env) {
PVideoFrame src = child->GetFrame(n, env);
PVideoFrame window = WindowVideo->GetFrame(n, env);
env->MakeWritable(&src);
unsigned char* srcp = src->GetWritePtr();
const int src_pitch = src->GetPitch();
const int src_width = src->GetRowSize();
const int src_height = src->GetHeight();
const unsigned char* windowp=window->GetReadPtr();
const int window_pitch = window->GetPitch();
const int window_width = window->GetRowSize();
const int window_height = window->GetHeight();
int w, i;
//--------LOOKUP is a loaded file 256x256x8bit gradient (65536 bytes long)--------
for (i=0; i < src_height; i++) {
for (w=0; w<src_width; w+=4) {
*(srcp + w+0) = LOOKUP [*(windowp + w+0)<<8 + *(srcp + w)];
*(srcp + w+1) = LOOKUP [*(windowp + w+1)<<8 + *(srcp + w+1)];
*(srcp + w+2) = LOOKUP [*(windowp + w+2)<<8 + *(srcp + w+2)];
*(srcp + w+3) = LOOKUP [*(windowp + w+3)<<8 + *(srcp + w+3)];
}
srcp+=src_pitch;
windowp+=window_pitch;
}
return src;
}
AVSValue __cdecl Create_SimpleSample(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new SimpleSample(args[0].AsClip(),
args[1].AsClip(),
args[2].AsInt(0),
args[3].AsInt(0),
args[4].AsInt(0),
env);
}
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("SimpleSample", "cciii", Create_SimpleSample, 0);
return "`SimpleSample' SimpleSample plugin";
}
so, where to put required instructions? i understood that in SimpleSample::SimpleSample(...) section. but what is proper syntax and how to deliver readed data to main procedure?
pozdrawiam (greetings)
PeaceAnt
24th November 2008, 12:37
OK, i did it myself. to bad we (?) didn't make a simple example as i expected. somebody could benefit from it.
and this is result of my plugin:
http://img81.imageshack.us/img81/6843/previewwd6.jpg (http://img81.imageshack.us/my.php?image=previewwd6.jpg)
http://img81.imageshack.us/img81/previewwd6.jpg/1/w720.png (http://g.imageshack.us/img81/previewwd6.jpg/1/)
pozdrawiam
Guest
24th November 2008, 14:30
OK, i did it myself. to bad we (?) didn't make a simple example as i expected. somebody could benefit from it. Then you should post the code for your solution. Or are you just a taker and not a giver?
PeaceAnt
24th November 2008, 15:18
i did it in other way. i just couldn't get help so i had to do it without loading a file. but you still can (should?) post that code. i think it's ten minut for you.
pozdrawiam
Guest
24th November 2008, 15:35
What code are you saying I should post? Examples of standard file IO?
PeaceAnt
24th November 2008, 16:00
no. i know my english isn't good, but i wrote it clearly in my posts i think. IanB understood it...
pozdrawiam
Guest
24th November 2008, 17:00
If it was as clear as you say, why don't I understand it?
You're telling me I should post some code. What code?
PeaceAnt
24th November 2008, 17:21
ok, once again:
where to open file and load it and how to deliver it to main procedure. where to put required instructions and what is proper syntax.
if it was so obvious i wouldn't ask...
Fizick
24th November 2008, 17:31
we do not say you, till you answered ths request :
http://forum.doom9.org/showthread.php?p=1213216#post1213216
:)
Guest
24th November 2008, 17:48
where to open file and load it Already answered by IanB above. You open it and load it in your filter constructor.
how to deliver it to main procedure Deliver "it"? Deliver what? As IanB explained, after you open the file, you can read it into memory. Then you can access that memory in your GetFrame() as needed.
where to put required instructions See above.
what is proper syntax Use Google to learn about standard file IO functions.
if it was so obvious i wouldn't ask... It's fine to ask, but after you've been given the answers, don't say nobody's helping you.
Aren't these answers enough to allow you to write the required code? If not, why not?
PeaceAnt
24th November 2008, 18:06
oh, come on! i wrote that i just learn c++ to write a few plugins. that's why. if you don't want help you don't need to.
Leak
24th November 2008, 18:55
In case you hadn't noticed - this forum is called "Avisynth development", not "Basic C++ 101"...
np: Rhythm & Sound - Trace (Rhythm & Sound)
krieger2005
24th November 2008, 19:09
Reading a File in general is really easy. You must just use the default IO-Functions of C++. Here is a link on a tutorial, one of thousands:
http://www.cplusplus.com/doc/tutorial/files.html
After that begin the specific part. You must know what to find where in the file. A File is like a long, long byte-chain. And your program must interpret this chain. You can't just say, that you want to load an array. How can you read in an 1-dimensional-byte-chain a 3D-array? The File by itself must be clear enough so you can interpret that content. And till none know the structure of the file no one can help you.
BTW @Fizick: Very nice way to get people to translate stuff :)
Fizick
24th November 2008, 19:15
I will try help :)
1. probably create some pointer to LookupTable right under:
//this params for further use
unsigned char * pLookUpTable;
2. Yes, file open and read in that place:
//<--------- OPEN AND READ HERE?------------------------
but I have no idea what is your "raw bimap". Windows BMP files usually have some header
(I never loaded them directly).
3. Anyway, when you loaded your "bitmap" to Lookup table, you can use it in your GetFrame function.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.