View Full Version : Help Avisynth programming
MattO
11th February 2003, 12:17
I am trying to understand the following avisynth plugin code (non 2.5):
----------
const int pitch = f->GetPitch(), row_size = f->GetRowSize(), height = f->GetHeight();
for(int y = 0; y < height; ++y){
for(int x = 0; x < row_size; ++x){
nextPixel1 = p[x];
nextPixel2 = p[x++];
----------
I have gathered 'row_size' is not the same as width but what does it refer to? How does it differ from 'f->GetWidth()'?
What do 'nextPixel1' & 'nextPixel2' refer to in the above?
Also what is 'pitch'?
thanks for any assistance
MattO
hakko504
11th February 2003, 12:26
If I understands it correctly, pitch is the length of the memory allocation corresponding to one line. width is the actual number of pixels. In YUY2 pich normally is equal to twice the width, but it can be larger if a crop has been made just before your operation. Let's say you open a DVD video in YUY2: width=720, pitch=1440. Crop it to 400 wide: new width=400, new pitch =1440! On the other hand, if you resize it to 400 wide then new width =400 and new pitch =800.
Oh, and maybe the AviSynth developers forum (http://www.avisynth.org/forum) is a better place for this kind of discussions, even though most people (or even all) visiting that forum are regulars here as well.
sh0dan
11th February 2003, 12:58
Width = width in pixels.
Rowsize = number of bytes in one line.
Pitch = distance from start of one line to the next in bytes.
vi->BytesFromPixels(n) size of n pixels in bytes - does NOT take pitch into consideration, so can only be used within a line.
For planar formats (YV12):
Aligned rowsize = width in bytes, always dividable with 8.
neuron2
11th February 2003, 14:35
Originally posted by MattO
I have gathered 'row_size' is not the same as width but what does it refer to?It is the width (number of pixels in the line) times the number of bytes per pixel, which depends on the color space. E.g., YUY2 has 4 bytes per 2 pixels, so row_size is twice the width.
How does it differ from 'f->GetWidth()'?See above.
What do 'nextPixel1' & 'nextPixel2' refer to in the above?The arrangement depends on the color space. For example, for YUY2 the byte layout for a group of 2 pixels is: Y1 U Y2 V.
Also what is 'pitch'?Pitch is the number of bytes between the starts of two successive lines. This may not be the same as the row_size (e.g., after a crop only the row_size is adjusted to avoid shifting stuff).
Hope that is a little more user friendly for newbies. :)
sh0dan
11th February 2003, 16:25
Oh - forgot - the almighty FAQ place:
DataStorageInAviSynth (http://www.avisynth.org/index.php?page=DataStorageInAviSynth)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.