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. |
30th October 2007, 19:34 | #1 | Link |
AviSynth plugger
Join Date: Nov 2003
Location: Russia
Posts: 2,183
|
(fast ?) Rotation plugin
I developed and released new simple Rotate plugin.
Rotate plugin makes frames rotation on any given angle. It may be used for perspective correction of amateur films or for special effect. Avisynth internal functions TurnLeft and TurnRight can rotate image on 90 degrees only. The Rotate plugin is faster than Zoom plugin and produces better quality images (IMO). Implemented Alan Paeth's method of bitmap rotation by means of 3 shears. Pixel (linear) interpolation is used at every shear. Size (scale) and aspect ratio of source picture are preserved. Based on rotation code from: http://treskunov.net/anton/Software/..._function.html Syntax and parameters of version 1.1: Rotate (clip, float "angle", int "width", int "height", int "color") first parameter is the source clip. angle is rotation angle in degrees clock wise. Default 0. width and height is size of destination output image. Default 0 is to be equal to input clip size. color is background color of part of clip. Integer or hex or global color constant like color_gray (see colors_rgb.avsi). Default 0 (color_black). Color formats: RGB32 (fast MMX), YV12 (not optimized) IMO, rotation filter should be Avisynth internal filter, but I am not sure about implementation Speed and bug reports are welcome as well as algo discussion.
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick I usually do not provide a technical support in private messages. Last edited by Fizick; 30th October 2007 at 19:39. |
30th October 2007, 23:36 | #2 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
A wayback link for Tobin Fricke, Rotation by Shearing (Damn domain name site gobblers )
Very nice find! Neat project! It's only BiLinear but it is a very sound start. |
31st October 2007, 04:05 | #3 | Link |
Registered User
Join Date: Mar 2002
Posts: 1,075
|
Memory access pattern on the vertical shear is nasty, but on something as simple as this who cares. Michael Unser has a paper on how accurate this approach can be compared to direct 2D interpolation (probably more than good enough most of the time).
http://bigwww.epfl.ch/publications/unser9502.pdf |
31st October 2007, 06:24 | #4 | Link |
AviSynth plugger
Join Date: Nov 2003
Location: Russia
Posts: 2,183
|
Some confusing with current version: YV12 rotation produce different (a little shifted) results from RGB32. Some reason is rotation direction change. Probably bug with center of rotation. I am not sure what is right.
Imagemagic avisynth port immaavs has rotate fuction, but it does not work for me. There are many other good projects http://www.leptonica.com/rotation.html
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick I usually do not provide a technical support in private messages. Last edited by Fizick; 31st October 2007 at 06:43. |
31st October 2007, 06:40 | #5 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
Direct 2D is very hard to MMX well, especially for higher order interpolation. Avery's VDub rotater is really devious. This offers a separable solution
And this triple shear implementation has heaps of room for improvement. i.e. get rid of the 90, 180 & 270 pre-rotates and adjust the core routine to work for all rotates (or do 4 core engines). Jazz the horizontal mmx code to do 2 or 4 pixels per loop. Jazz the the vertical MMX code to process across the image instead of down (I estimate any vertical code I wrote would be faster than the horizontal particularly for planar, in which case change the main code to be shear-V, shear-H, shear-V). Junk the width and height options and always output maximal size, this loses all the edge testing code in the inner loops, if really required just do as an implicit Crop on the output. To improve accuracy, the multipoint interpolation could be stolen from the resizer core. Also shear-1 could output 16bit intermediate, shear-2 could process 16bit and shear-3 could process 16bit and finally output 8bit. @Fizick, To test the rotate do Code:
A=Last Rotate(30.0) Rotate(30.0) Rotate(30.0) TurnRight() Subtract(A) Code:
A=Last Rotate(-30.0) Rotate(-30.0) Rotate(-30.0) TurnLeft() Subtract(A) Code:
A=Last Rotate(45.0) Rotate(45.0) TurnRight() Subtract(A) Code:
A=Last Rotate(-45.0) Rotate(-45.0) TurnLeft() Subtract(A) Last edited by IanB; 31st October 2007 at 06:46. |
31st October 2007, 15:22 | #7 | Link |
AviSynth plugger
Join Date: Nov 2003
Location: Russia
Posts: 2,183
|
There are also EffectsMany plugin by VCMohan
http://avisynth.org/vcmohan/EffectsM...tRotation.html its is even slower (I do not see some sourcecode) Zoom, but has nice options set.
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick I usually do not provide a technical support in private messages. |
31st October 2007, 20:55 | #8 | Link |
Registered User
Join Date: Nov 2001
Posts: 291
|
First of all once more thanks for this contribution
You can find most of vcmohan's sources at: http://avisynth.org/vcmohan/index.html You should look for them in EffectsMany and TransAll Relative to the simplest rotation case 180(no resize needed) I have already implemented (Rotate180) for RGB32, YUY2 and YV12 mmx,isse and sse2 and a plain code for RGB24 Source Code and dll: http://www.iespana.es/Ardaversions/ROTATES_151.7z You can follow in this thread http://forum.doom9.org/showthread.php?t=121066 This work was mainly intended to study write combining techniques and working in place when algo and avisynth conditions were appropiate. You can find a L2 cache size detection code used to choose when using non temporal instruccions. It is not a fully finished work but I hope you can find something usefull from it. Once more thanks ARDA |
1st November 2007, 05:48 | #9 | Link |
AviSynth plugger
Join Date: Nov 2003
Location: Russia
Posts: 2,183
|
I discover, that used formulas are not precise (rounding to integer pixel). Weight of first pixel is not correct.
That is why the origin (center) or rotation is not stable. may be sombody (Mfa) knows the correct reference article?
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick I usually do not provide a technical support in private messages. Last edited by Fizick; 25th July 2008 at 18:24. |
1st November 2007, 17:43 | #10 | Link |
Registered User
Join Date: Mar 2002
Posts: 1,075
|
Don't have the original paper ... but once you have the decomposition into shears I don't really see why you need more information.
First shear : x' = x - tan (theta/2) * y Second shear : y' = y + sin(theta) * x Third shear : x' = x - tan (theta/2) * y Everything else follows from that. Netpbm and Freeimage implement the algorithm too BTW. |
1st November 2007, 18:44 | #11 | Link |
AviSynth plugger
Join Date: Nov 2003
Location: Russia
Posts: 2,183
|
I know formulas. I say about implementation.
I need more info because of I am lazy and I do not want calculate myself precise (float) offsets of center and corners (pixels) after every step. I found codes for pixel pecision only (i say about position of origin of rotation). It is simple. Pixels are discrete, shears are not. I know how to do first shear correctly (i implement it in prepared next version). But next steps parameters must be changed too and unclear for me how. Anyway, Shear may be useful Avisynth function too.
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick I usually do not provide a technical support in private messages. |
14th November 2007, 01:07 | #12 | Link |
Registered User
Join Date: Apr 2005
Posts: 213
|
Nice plugin. I'm using it for image editing with AviSynth. ;-)
|
2nd July 2008, 09:35 | #13 | Link |
Resize Abuser
Join Date: Apr 2005
Location: Seattle, WA
Posts: 623
|
Using 1.3 & 2.5.8 RC2
On frame 125 I get an Access Violation error with this script in MPC and AvsP. Code:
ColorBars().Trim(0,200) Animate(0,200, "Rotater" ,0.0, 360.0) Function Rotater(clip c, float x) { c.Rotate_Rotate(x) Subtitle(String(x)) } YV12 seems to have even more problems.
__________________
Mine: KenBurnsEffect/ZoomBox CutFrames Helped: DissolveAGG ColorBalance LQ Animation Fixer Last edited by mikeytown2; 2nd July 2008 at 09:42. |
2nd July 2008, 18:01 | #14 | Link |
AviSynth plugger
Join Date: Nov 2003
Location: Russia
Posts: 2,183
|
bug with angle=225 is confirmed.
Fixed in v.1.3.1
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick I usually do not provide a technical support in private messages. |
2nd July 2008, 19:32 | #15 | Link |
Resize Abuser
Join Date: Apr 2005
Location: Seattle, WA
Posts: 623
|
Thanks for fixing that! I have an example for YV12 that goes green and crashes on frame 206
Code:
ColorBars().Trim(0,999).ConvertToYV12() Animate(0,999, "Rotater" ,0.0, 360.0) Function Rotater(clip c, float x) { c.Rotate_Rotate(x) Subtitle(String(x)) } 105.785358 <= Angle >= 074.214642 254.214638 >= Angle <= 285.785354 15.7853 from 90 and 270 are the problem areas
__________________
Mine: KenBurnsEffect/ZoomBox CutFrames Helped: DissolveAGG ColorBalance LQ Animation Fixer Last edited by mikeytown2; 2nd July 2008 at 19:35. |
25th July 2008, 19:20 | #16 | Link |
AviSynth plugger
Join Date: Nov 2003
Location: Russia
Posts: 2,183
|
fixed stupid bug with YV12 in v.1.3.2
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick I usually do not provide a technical support in private messages. |
25th July 2008, 20:13 | #17 | Link |
Resize Abuser
Join Date: Apr 2005
Location: Seattle, WA
Posts: 623
|
Thanks again for fixing the YV12 bug!
I have a feature request... Any chance of being able to specify the center of rotation (x,y)?
__________________
Mine: KenBurnsEffect/ZoomBox CutFrames Helped: DissolveAGG ColorBalance LQ Animation Fixer |
26th July 2008, 07:23 | #18 | Link | |
Registered User
Join Date: Jul 2003
Location: India
Posts: 890
|
Rotation in EffectsMany plugin has the facility to specify center of rotation.
Quote:
|
|
26th July 2008, 20:35 | #19 | Link |
Resize Abuser
Join Date: Apr 2005
Location: Seattle, WA
Posts: 623
|
@vcmohan any chance of changing some of the int inputs into floats (rotation,x,y)?
I did a comparison of the different rotation plugin's for AviSynth a little while back http://forum.doom9.org/showthread.ph...53#post1146653 I didn't know about Fizick's Rotate plugin when i did that test. Fizick's Rotate plugin had the best speed/quality trade off; HQ and still fast. I am currently looking into rotation plugin's for developing this transition script further... http://forum.doom9.org/showthread.ph...61#post1157561 Thanks for all the hard work both of you guys do!
__________________
Mine: KenBurnsEffect/ZoomBox CutFrames Helped: DissolveAGG ColorBalance LQ Animation Fixer |
27th July 2008, 09:29 | #20 | Link |
Registered User
Join Date: Jul 2003
Location: India
Posts: 890
|
Now EffectRotation function of EffectsMany plugin accepts angle in float format. I do not presently thinking of changing the center coordinates x and y also to float. It probably will entail almost complete recoding.
|
Thread Tools | Search this Thread |
Display Modes | |
|
|