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. |
13th March 2003, 00:19 | #22 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
Here is Version 1.2 which puts a white square in the middle of the frame - wow
It reverts to just handling RGB24 colourspace for simplicity. http://www.geocities.com/siwalters_u...lesample12.zip The next version will have variable parameters and then I'll add in the code for the other colourspaces. regards Simon @Wilbert Or just right-click and use Save Target As
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
13th March 2003, 07:49 | #23 | Link |
Registered User
Join Date: Apr 2002
Posts: 67
|
I've written quite a few vdub filters, and I've looked at the avisynth sdk a couple of times and what has me stumped is where are the equivalents to start/end proc that you have in vdub? An example that does some basic buffering would be helpful, specifically as to where should you allocate/free memory.
|
13th March 2003, 08:56 | #24 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
@Leuf
I asked a very similar question just a few days ago and the answer was that any static variables are defined in the constructor but I'm in the middle of porting my PFR filter and haven't yet debugged it so I can't tell whether I've got it right yet. Once I have I'll point out how I did it regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
13th March 2003, 10:35 | #25 | Link |
Retired AviSynth Dev ;)
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
|
Added destructor, and some member variables:
Code:
class SimpleSample : public GenericVideoFilter { // SimpleSample defines the name of your filter class. // This name is only used internally, and does not affect the name of your filter or similar. // This filter extends GenericVideoFilter, which incorporates basic functionality. // All functions present in the filter must also be present here. public: // This defines that these functions are present in your class. // These functions must be that same as those actually implemented. // Since the functions are "public" they are accessible to other classes. // Otherwise they can only be called from functions within the class itself. SimpleSample(PClip _child, IScriptEnvironment* env); // This is the constructor. It does not return eny value, and is always used, // when an instance of the class is created. // Since there is no code in this, this is the definition. ~SimpleSample(); // The is the destructor. This is called when the filter is destroyed. PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); // This is the function that AviSynth calls to get a given frame. // So when this functions gets called, the filter is supposed to return frame n. private: // This is where you put the class variables. int box_width; int box_height; int box_x, box_y; }; /*************************** * The following is the implementation * of the defined functions. ***************************/ SimpleSample::SimpleSample(PClip _child, IScriptEnvironment* env) : GenericVideoFilter(_child) { // This is the implementation of the constructor. // The child clip (source clip) is inherited by the GenericVideoFilter, // where the following variables gets defined: // PClip child; // Contains the source clip. // VideoInfo vi; // Contains videoinfo on the source clip. if (!vi.IsRGB24()) // is input not RGB24 env->ThrowError("SimpleSample: input to filter must be in RGB24 colourspace"); } SimpleSample::~SimpleSample() { // This is where you can deallocate any memory you might have used. }
__________________
Regards, sh0dan // VoxPod |
13th March 2003, 10:52 | #26 | Link |
Avisynth 3.0 Developer
Join Date: Jan 2002
Location: France
Posts: 639
|
Beware of the confusion between static variables (defined with the word static) and normal member variables.
static variables are kinda global variables, but in the namespace and scope of the class. They are called static because they don't depend of the existence of class instances to exist. They always exist and are unique, you write : myClass::myStaticVar and not MyObject.myVar You can use static in definition code too, it is used to define vars with global lifetime without worrying about polluting the :: namespace. (don't have to woory about choosing a smart name who won't be confused..) exemple : Code:
int CallCount() { //named as it does static int count = 0; //this init is done once at the lodaing of the code return ++count; } Better programming to limit access to the good guy by putting it in the right place, that's the same idea with static var in class. As for constructor/destructor its a symetric process. Constructor builds members, create objects via new (new char[] for memory alloc generally). Detructor destroys members (implicitly) and delete object created by new. Btw implicit destuction is much safer : if the constructor fails due to an exception, construction is ended, all members will be correctly destroyed, but pointers won't be deleted but leaked... :/ If you throw the exception yourself, you may explicitly destroy what must (but it's annoying and you may forget (ie one day you will)). But if the exception is thrown by a called method (maybe you don't even know it can happen) you are ******. To avoid that, one can use smart ptr class (who automatically delete the ptr they hold when leaving context) like std::auto_ptr Edit: crossposted with sh0dan Last edited by Guest; 14th March 2003 at 00:44. |
14th March 2003, 01:21 | #28 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
Here is SimpleSample 1.3
http://www.geocities.com/siwalters_u...lesample13.zip It just adds in one parameter to vary the size of the square. Syntax: SimpleSample(clip,[size]) I intend to just plod on with now modifying it for extra colourspaces before trying to introduce any advanced stuff about global/static variables, buffering etc - remember, it is called SimpleSample @shOdan I've added in the bits from your last post about the destructor but not the private member variables. The code I've used to use a parameter is a combination of the code I normally use but modified in the light of what I'm learning from this thread about constructors. I'd welcome any comments (to put in a 1.3a version) and real comments to me about the way I've done it,which is just to copy the way I see others have done . @Bidoche Good information and one day I hope to understand more than the 10% of it that I do at the moment
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
14th March 2003, 12:13 | #29 | Link |
Avisynth 3.0 Developer
Join Date: Jan 2002
Location: France
Posts: 639
|
@siwalters
Rome was not built in one day. Btw, maybe you could precise that pitch must always be fetched after the read/write ptr. I am not totally sure for 2.0/2.5 but in 3.0 a GetWritePtr may reallocate the picture and change the pitch. |
14th March 2003, 19:22 | #30 | Link |
Retired AviSynth Dev ;)
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
|
Pitch only has to be refreshed after an env->NewVideoFrame().
GetWritePtr() cannot modify pitch in 2.0/2.5!
__________________
Regards, sh0dan // VoxPod Last edited by sh0dan; 14th March 2003 at 19:25. |
15th March 2003, 01:57 | #31 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
Oops Bugfix release
Version 1.3a available here http://www.geocities.com/siwalters_u...esample13a.zip The change is from Code:
for (w = (dst_width/2 - SquareSize/2)*3; w < (dst_width/2 + SquareSize/2)*3; w+=3) { to for (w = dst_width/2 - SquareSize*3/2; w < dst_width/2 + SquareSize*3/2; w+=3) { regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
15th March 2003, 03:01 | #32 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
Version 1.4 available here
http://www.geocities.com/siwalters_u...lesample14.zip Simply adds in RGB32 code. regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
15th March 2003, 20:08 | #33 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
V1.5 with YUY2 colourspace code - 1 more to go
http://www.geocities.com/siwalters_u...lesample15.zip regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
15th March 2003, 21:34 | #34 | Link |
Retired AviSynth Dev ;)
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
|
You could use vi->BytesFromPixels(1) instead of having separate loops for RGB24 and RGB32.
Much cleaner, and demonstrates more of the capabilities IMO.
__________________
Regards, sh0dan // VoxPod |
15th March 2003, 22:02 | #35 | Link |
Registered User
Join Date: Feb 2003
Posts: 299
|
Hi siwalters.. sh0dan and Belgabor and others..
Just wanted to say THANKS for the idea of this thread. Something I've ben looking for, for a long time. siwalters, great idea and approach, how you build-on as you go. Nice and slow. Great! Thanks. Maybe some day, I'll return w/ a filter or too to share. Please continue to keep up the good work. -vhelp
__________________
ESC K7S5A / XP 1800+ / Windows 98 ADVC-100[dvio] / WTVGO[avio] / DC10+[avio] / Canon ZR-10 / Delphi 6 Personal / JVC S-VHS HR-S3910U / Durabrand SSS w/ DVD Player STS75E / Sony TRV-22 FithElement/Dogma/BladeRunner/Contact |
16th March 2003, 09:28 | #36 | Link | |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
@sh0dan
Quote:
So I went looking through the FilterSDK until I found this Is this information/code new to 2.5 or has it always been around? And therefore does it mean there is a GetRowWidth() function that can be called? And could you give me/us an example of using vi->BytesFromPixels(1) please? regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html Last edited by Si; 16th March 2003 at 11:00. |
|
16th March 2003, 12:23 | #37 | Link |
Avisynth 3.0 Developer
Join Date: Jan 2002
Location: France
Posts: 639
|
Code:
// This will return the position of the upperleft pixel in YUY2 images, // and return the lower-left pixel in RGB. Is it really vital ? |
16th March 2003, 12:42 | #38 | Link |
Retired AviSynth Dev ;)
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
|
BytesFromPixels(int n) has always been around. Have a look at avisynth.h to see the funtions you can use.
Example (from fliphorizontal) Code:
int bpp = vi.BytesFromPixels(1); for (int y=0; y<h;y++) { // Loop for RGB and planar luma. for (int x=0; x<row_size; x+=bpp) { for (int i=0;i<bpp;i++) { dstp[x+i] = srcp[-x+i]; } } srcp += src_pitch; dstp += dst_pitch; } @Bidoche: RGB is always flipped in AviSynth, and every filter processes it as such.
__________________
Regards, sh0dan // VoxPod |
16th March 2003, 15:36 | #40 | Link |
Retired
Join Date: Jan 2002
Location: Netherlands
Posts: 1,529
|
Hi,
Something is not entirely clear to me in the following piece of code that deals with YUY2 colorspace. Code:
dstp = dst->GetWritePtr(); // reset the destination pointer to the top, left pixel. (YUY2 colourspace only) dstp = dstp + (dst_height/2 - SquareSize/2)*dst_pitch; // move pointer to SquareSize/2 lines from the middle of the frame; int woffset = dst_width/8 - SquareSize/4; // lets precalulate the width offset like we do for the lines. for (h=0; h < SquareSize;h++) { // only scan SquareSize number of lines for (w = 0; w < SquareSize/2; w+=1) { // only scans the middle SquareSize pixels of a line *((unsigned int *)dstp + woffset + w) = 0x80FB80FB; // Set Y1 and Y2 to max, U and V to no colour. } // LSB = Y1, MSB = V dstp = dstp + dst_pitch; } |
Thread Tools | Search this Thread |
Display Modes | |
|
|