View Full Version : code loop?
Mug Funky
12th March 2004, 17:03
hey all. i recently discovered masktools' "yv12convolution" and discovered it could do really huge convo matrices...
so i decided to use it for low-passing.
doing this requires feeding in a string of numbers grabbed off a sine curve. this has to be re-calculated by me for every "radius" i want. so i thought it'd be cool to have a function spit this string straight into YV12convolution and save me the bother.
now the problem is i don't see how i can do that without a while loop inside avisynth.
i don't think this is possible, as avisynth is not really designed for programming of this sort.
am i going to have to learn C? :P
oof
12th March 2004, 18:52
Scriptclip can be made to behave like a loop
Manao
12th March 2004, 19:25
You can use recursive function : Function loop(string s, int stop)
{
return (stop == 0) ? s : string(stop) + " " + loop(s,stop-1)
}
return messageclip(loop("", 3))
SoonUDie
12th March 2004, 19:38
I suggest you learn C anyways :D
Mug Funky
12th March 2004, 19:46
manao: cheers! unfortunately i've already made hand calculated strings for radii up to 16...
not too elegant, but it works
MrTVideo
13th March 2004, 07:49
As a thought, Basic is a lot easy to concatenate strings and handles math quite well. and you can use it to write a very complicated avs script very fast. I am still finding out what the syntax of AVIsynth is yet. So what I have been doing is feed the script on a plate I think that it allows 64k(Could be wrong) that is one hell of a mouthfull as a text file.
esby
13th March 2004, 13:49
If you just need to do some filters,
learn c++,
you won't have to wait for the avisynth_c.h...
(which shall be separate plugin starting from 2.55 if i'm not wrong...)
esby
Wow, so it would actually be possible to create a piecemeal supersampler in AVS? Ugh.
digitize
13th March 2004, 17:26
@mf "piecemeal supersampler"?
Originally posted by digitize
@mf "piecemeal supersampler"?
Splits the image up in tiles and enlarges them seperately, then pieces them back together. Makes for images that fit into the processor cache, speeding up things alot compared to dragging 7MB frames through the processor all the time.
Soulhunter
13th March 2004, 20:07
Originally posted by mf
Wow, so it would actually be possible to create a piecemeal supersampler in AVS? Ugh. Hehe, maybe a faster SharpResize function... :D
Bye
Didée
13th March 2004, 20:08
Originally posted by mf
Splits the image up in tiles and enlarges them seperately, then pieces them back together. Makes for images that fit into the processor cache, speeding up things alot compared to dragging 7MB frames through the processor all the time.
Already tried that before. But it seems a no-go. Once you make enough tiles to get nice little tile images fitting into the cache, the simultaneously created overhead for cropping & re-stacking together, initiating filters, etc., grows also, undoing most of the theoretical speed advantage.
Moreover, for many filters, you need to "overscale" the tiles, to get the borders of the tiles processed correctly. This is even more overhead, as you were filtering big parts of a frame twice. And you cannot re-use those additional borders of the tiles when processing the neighbor tiles - that just can't be fiddled with an AviSynth script in a senseful way.
Within dedicated filter plugins, that's another story: I assume there it is often possible to re-use already processed parts in another step, if your code is nifty enough.
My 2 cents
- Didée
I know Didee. Just look at how slow AddPadding is - and how fast a coded equivalent can be. Just thinking of the thought that it's possible to script makes me shiver.
Mug Funky
15th March 2004, 08:24
well, this has kinda drifted off topic a tad, but no matter.
here's a sinusoidal blur based on YV12convolution from masktools.
works flawlessly up to a radius of ~12, then it goes a little weird occasionally. good on radius 16 though. i think this is due to an oddity of yv12convo (maybe manao wasn't expecting such huge matrices to be fed into it...)
function gauss (clip c,int "radius",bool "conv") {
radius=default(radius,4)
conv=default(conv,false)
Function siney(string s,int stop,int len)
{
eqn = string(round(256*pow(sin(pi*stop/len),2)))
return (stop == 0) ? s : siney(s,stop-1,len) + "," + eqn
}
matrix=siney("",radius*2,radius*2)
matrix=matrix.midstr(2,(matrix.strlen()-3))
(conv==false)?c.bilinearresize(4*(c.width/(radius*2)),4*(c.height/(radius*2)))
\.bicubicresize(c.width,c.height,1,0):
\c.yv12convolution(horizontal=matrix,vertical=matrix,Y=3,U=3,V=3,usemmx=true)
}
"radius" controls the radius of the blur (duh)
"conv" toggles between fast bicubicresize blur (default) and yv12convo based blur (ranges from slow to extremely slow)
seeing as there's not much visual difference between these two blur modes i decided to give the option of a slower one... but a true sine-based blur works much better for deblocking purposes.
the above code is at the core of most of my custom scripts you might find around here... (well, on my machine anyway, until i update the ones here)
thanks to manao for helping me with the loop thing (and writing masktools of course)
Manao
15th March 2004, 10:27
I found what was wrong. While computing, a value is going over 2^31... I can't do nothing about that, that would slow down the process for 'classic' matrices. I'll add that in the documentation of the next release, and I may add a mode where computations are made in floats.
Anyway, thanks for the kind words :)
Mug Funky
15th March 2004, 12:22
problem solved, or rather worked around :)
to get my matrix, each float was multiplied by 256, which is obviously a bit much for a large matrix.
i added a "precision" option which changes this multiplier... specify how many bits of precision you want for the matrix. smaller values give larger possible blur values, and (very) slightly less precise blurs. at large radiuses this means very little...
here's the modded code:
function gauss (clip c,int "radius",bool "conv",int "precision") {
radius=default(radius,4)
conv=default(conv,false)
precision=default(precision,8)
mul=int(pow(2,precision))
Function siney(string s,int stop,int len,int mul)
{
eqn = string(round(mul*pow(sin(pi*stop/len),2)))
#(stop == 0) ? s : eqn + "," + siney(s,stop-1,len)
return (stop == 0) ? s : siney(s,stop-1,len,mul) + "," + eqn
}
matrix=siney("",radius*2,radius*2,mul)
matrix=matrix.midstr(2,(matrix.strlen()-3))
(conv==false)?c.bilinearresize(4*(c.width/(radius*2)),4*(c.height/(radius*2)))
\.bicubicresize(c.width,c.height,1,0):
\c.yv12convolution(horizontal=matrix,vertical=matrix,Y=3,U=3,V=3,usemmx=true)
}
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.