06-30-2022, 12:14 PM | #1 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
Overlay: image with rotation! (updated)
Hey! Here is a quick hack of the "Overlay:image" preset that includes rotation of the overlay. I always wondered why rotation was not part of the stock preset since the "Basic helper: track opacity/zoom/pan" does it. So I extracted the magic formula from o/z/pan and put it in the overlay:image instead. Changing the rotation axis was easy so it's included. If your image gets cut while rotating just increase the "extra room". Code:
//Image overlay w/rotation // rotation hack by papagirafe //@param opacity 'opacity' 1 //@param zoom 'zoom' 0 -15 15 0 //@param xoffs 'X offset' 0 -1 1 0 0.01 //@param yoffs 'Y offset' 0 -1 1 0 0.01 //@param rota "rotation" 0 -360 360 0 0.1 //@param cxoff 'rot axis x offset' 0 -1 1 0 0.01 //@param cyoff 'rot axis y offset' 0 -1 1 0 0.01 //@param9:filter 'filter' 0 0 1 0.5 1 //@param use_srca 'alpha channel' 1 0 1 0.5 1 //@param sc "extra room rot" 1 1 8 4 0.1 img1=input_track(0); img2=0; use_srca && img2 != img1 ? colorspace='RGBA'; input_info(img1,img1w,img1h) && project_wh_valid===0 ? ( project_w = img1w; project_h = img1h; ); a = opacity < 0.01 ? 0 : opacity > 0.99 ? 1 : opacity; img2 != img1 && input_info(img2,sw,sh) ? ( gfx_blit(img1,0); a>0?( gfx_a=a; gfx_mode = (filter>0.5 ? 256 : 0)|(use_srca?0x10000:0); z = 10^(zoom/10); dw = (sw*z)|0; dh = (sh*z)|0; x = (project_w - dw + (project_w + dw)*xoffs)*.5; y = (project_h - dh + (project_h + dh)*yoffs)*.5; /*sc=2.0;*/ sc2=sc*.5 - 0.5; gfx_rotoblit(img2,rota*$pi/180,(x-dw*sc2)|0,(y-dh*sc2)|0,dw*sc,dh*sc, -sw*sc2, -sh*sc2, sw*sc, sh*sc,0,cxoff*dw|0,cyoff*dh|0); ); ); Code:
//Basic helpers: crop //by papagirafe //@param cl "crop left" 0 0 1 0.5 0.001 //@param cr "crop right" 0 0 1 0.5 0.001 //@param ct "crop top" 0 0 1 0.5 0.001 //@param cb "crop bottom" 0 0 1 0.5 0.001 //@param6:amode "use alpha" 0 0 1 0.5 1 amode?(colorspace='RGBA';mode=0x10000); E=0xFFFE; input_info(0,w,h); cl=(cl*w)&E;cr=(cr*w)&E;ct=(ct*h)&E;cb=(cb*h)&E; cx=cl;cy=ct; cw=w-(cl+cr);ch=h-(ct+cb); project_w=cw; project_h=ch; gfx_set(0,0,0,1,mode,-1); gfx_blit(0,1,0,0,cw,ch,cx,cy,cw,ch); Last edited by papagirafe; 07-11-2022 at 02:49 PM. |
07-11-2022, 02:47 PM | #2 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
improved version, automatic extra room
Hiho! the manual "extra room" really bugged me, so I added the math to automatically calculate the optimal value.
Code:
//Image overlay w/rotation // added rotation v1.1 by papagirafe //@param opacity 'opacity' 1 //@param zoom 'zoom' 0 -15 15 0 //@param xoffs 'X offset' 0 -1 1 0 0.01 //@param yoffs 'Y offset' 0 -1 1 0 0.01 //@param rota "rotation" 0 -360 360 0 0.1 //@param cxoff 'rot axis x offset' 0 -1 1 0 0.01 //@param cyoff 'rot axis y offset' 0 -1 1 0 0.01 //@param9:filter 'filter' 0 0 1 0.5 1 //@param use_srca 'alpha channel' 1 0 1 0.5 1 function set_origin(ox,oy)(this.ox=ox;this.oy=oy); function rotate_coord(x,y,rota) instance(r,phi) ( this.x=x-this.ox; this.y=y-this.oy; r=sqrt(this.x^2+this.y^2); phi=2*atan(this.y/(this.x+r))+rota; this.x=r*cos(phi); this.y=r*sin(phi); ); function calc_extra_rot(w,h,rota,ox,oy) local(a,rx,ry,rxmax,rymax,ox,oy) ( rxmax=rymax=0; rx=w>>1; ry=h>>1; ox=(ox*w)|0; oy=(oy*h)|0; a.set_origin(rx,ry); a.rotate_coord(0+ox,0+oy,rota); abs(a.x)>rxmax?rxmax=abs(a.x|0); abs(a.y)>rymax?rymax=abs(a.y|0); a.rotate_coord(w+ox,0+oy,rota); abs(a.x)>rxmax?rxmax=abs(a.x|0); abs(a.y)>rymax?rymax=abs(a.y|0); a.rotate_coord(0+ox,h+oy,rota); abs(a.x)>rxmax?rxmax=abs(a.x|0); abs(a.y)>rymax?rymax=abs(a.y|0); a.rotate_coord(w+ox,h+oy,rota); abs(a.x)>rxmax?rxmax=abs(a.x|0); abs(a.y)>rymax?rymax=abs(a.y|0); max(rxmax/rx,rymax/ry); ); img1=input_track(0); img2=0; use_srca && img2 != img1 ? colorspace='RGBA'; input_info(img1,img1w,img1h) && project_wh_valid===0 ? ( project_w = img1w; project_h = img1h; ); a = opacity < 0.01 ? 0 : opacity > 0.99 ? 1 : opacity; img2 != img1 && input_info(img2,sw,sh) ? ( gfx_blit(img1,0); a>0?( gfx_a=a; gfx_mode = (filter>0.5 ? 256 : 0)|(use_srca?0x10000:0); rota*=$pi/180; z = 10^(zoom/10); dw = (sw*z)|0; dh = (sh*z)|0; x = (project_w - dw + (project_w + dw)*xoffs)*.5; y = (project_h - dh + (project_h + dh)*yoffs)*.5; sc=calc_extra_rot(dw,dh,rota,cxoff,cyoff); sc2=sc*.5 - 0.5; gfx_rotoblit(img2,rota,(x-dw*sc2)|0,(y-dh*sc2)|0,dw*sc,dh*sc, -sw*sc2, -sh*sc2, sw*sc, sh*sc,0,(cxoff*dw)|0,(cyoff*dh)|0); ); ); Last edited by papagirafe; 07-11-2022 at 04:58 PM. Reason: minor corrections |
07-15-2022, 04:28 AM | #3 |
Human being with feelings
Join Date: Oct 2009
Location: France
Posts: 745
|
Nice, thank you very much.
|
07-15-2022, 06:06 AM | #4 |
Human being with feelings
Join Date: Aug 2020
Location: Brasil
Posts: 690
|
|
Thread Tools | |
Display Modes | |
|
|