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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th March 2003, 11:56   #21  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Thanks!
Wilbert is offline   Reply With Quote
Old 13th March 2003, 00:19   #22  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 13th March 2003, 07:49   #23  |  Link
Leuf
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.
Leuf is offline   Reply With Quote
Old 13th March 2003, 08:56   #24  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 13th March 2003, 10:35   #25  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
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
sh0dan is offline   Reply With Quote
Old 13th March 2003, 10:52   #26  |  Link
Bidoche
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;
}
This could have been with count global but then it risk external modifications :/
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.
Bidoche is offline   Reply With Quote
Old 13th March 2003, 11:04   #27  |  Link
jonny
Registered User
 
jonny's Avatar
 
Join Date: Feb 2002
Location: Italy
Posts: 876
I think this thread is great for programmers entering in the AviSynth development side for the first time (i'm one of these ^^')

What about make it sticky?
jonny is offline   Reply With Quote
Old 14th March 2003, 01:21   #28  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 14th March 2003, 12:13   #29  |  Link
Bidoche
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.
Bidoche is offline   Reply With Quote
Old 14th March 2003, 19:22   #30  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
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.
sh0dan is offline   Reply With Quote
Old 15th March 2003, 01:57   #31  |  Link
Si
Simply me
 
Si's Avatar
 
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) {
The first version worked for some reason but proved to be wrong when I tried modifying it for use with RGB32

regards
Simon
Si is offline   Reply With Quote
Old 15th March 2003, 03:01   #32  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 15th March 2003, 20:08   #33  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 15th March 2003, 21:34   #34  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
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
sh0dan is offline   Reply With Quote
Old 15th March 2003, 22:02   #35  |  Link
vhelp
Registered User
 
vhelp's Avatar
 
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
vhelp is offline   Reply With Quote
Old 16th March 2003, 09:28   #36  |  Link
Si
Simply me
 
Si's Avatar
 
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
@sh0dan
Quote:
vi->BytesFromPixels(1)


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

Last edited by Si; 16th March 2003 at 11:00.
Si is offline   Reply With Quote
Old 16th March 2003, 12:23   #37  |  Link
Bidoche
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.
Arghhh... I didn't take this into account in the 3.0 code, and it won't be easily fixed (an ugly hack maybe)
Is it really vital ?
Bidoche is offline   Reply With Quote
Old 16th March 2003, 12:42   #38  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
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;
  }
This is to avoid having separate loops for RGB24, RGB32 and YV12 (YUY2 is different due to the chroma placement).

@Bidoche: RGB is always flipped in AviSynth, and every filter processes it as such.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 16th March 2003, 13:47   #39  |  Link
Bidoche
Avisynth 3.0 Developer
 
Join Date: Jan 2002
Location: France
Posts: 639
@sh0dan

Are you saying that it is necessary to be flipped, or that the code update cost will be too much ?
Bidoche is offline   Reply With Quote
Old 16th March 2003, 15:36   #40  |  Link
Acaila
Retired
 
Acaila's Avatar
 
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; 
		}
This is probably a newbie question, but then I am a newbie at coding so I hope you'll forgive me. According to this page Y has a range of 16-235. However to make the square white you're setting it to FB (=251), why aren't you setting it to EB (=235) instead?
Acaila is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 14:59.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.