Old 01-11-2021, 01:47 AM   #1
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 606
Default Help with Video processor zoom/pan script

My wife does a bunch of video editing of virtual choir these days, so I got her going with reaper, which has been awesome.

When we started in the Spring, I cobbled together a program for that purpose (she needed more control than just the auto-choir-layout programs here) and it has been working. but it's awkward, as it zooms and pans fromm the upper left, and it's easy to zoom too far out, or pan too far across. And so I'm rewriting it.

What I want is a viewport w,h,x,y that can be set absolutely, and then zoom and pan for the image within. The zoom and pan should be limited so that you can't move the image view out of frame. I have this all working except for one bit.

Right now, the pan is not properly limited in one direction. That direction is the smaller of the percentages for width and height. More in the code below.

Anyway, it's really close, and I'm hoping a code wizard here can point out my error, but even with the bug, it's still very quick, especially if you assign pan to x,y dragging in the video window, and zoom to the mouse wheel. Better for her purposes than anything else I've found...

Code:
//. Moon Video Controls
//We want to specify the top, bottom, width and height of the video view.
//This will never change as zoom and pan change
// 'name'                       [defval minval maxval centval  step]
//@param 1:opacity 'Opacity'       1       0      1     0.5    0.01;
//@param 2:zoom 'Zoom'             1       1      5    2.25    0.05
//@param 3:x_pan 'Horiz Pan'       0      -1      1      0     0.01
//@param 4:y_pan 'Vert Pan '       0      -1      1      0     0.01
//@param 6:coarse_y 'Bottom/Top'  .5       0      1     .5     0.01 
//@param 7:coarse_x 'Left/right'  .5       0      1     .5     0.01 
//@param 8:coarse_h 'Height'      .5       0      1     .5     0.01
//@param 9:coarse_w 'Width'       .5       0      1     .5     0.01
//@param 11:fine_y 'Top-fine'      0      -1      1      0     0.01
//@param 12:fine_x 'Left-fine'     0      -1      1      0     0.01
//@param 13:fine_h 'Height-fine'   0      -1      1      0     0.01
//@param 14:fine_w 'Width-fine'    0      -1      1      0     0.01
//@param 16:asp 'Keep Aspect'      1       0      1      0      1;

img1=0;
img2=input_track(0);  //this is the actual image
gfx_blit(img2);
input_info(img1, sourceW, sourceH);
fine = .01;

//HEIGHT AND WIDTH
percentH = (coarse_h + (fine * fine_h));
percentW = (coarse_w + (fine * fine_w));
percentX = (coarse_x + (fine * fine_x));
percentY = 1 - (coarse_y + (fine * fine_y));  //for more natural knob motion

//dont allow frame to go off the edges
rangeX = percentX * (1 - percentW);
rangeY = percentY * (1 - percentH);

//convert percents to pixels
frameH = percentH * project_h;
frameW = percentW * project_w;
frameX = rangeX * project_w;
frameY = rangeY * project_h;

//don't let us zoom out too far, 
//the minimum zoom should be larger for smaller frames
smaller = min(percentH, percentW);
zoomAdj = zoom / smaller;

viewW = sourceW / zoomAdj;
viewH = sourceH / zoomAdj;

//this code works pefectly for the minimum dimension 
//in the denominator of zoomAdj, but allows way too much in the max dim.
xPanAdj = x_pan;
yPanAdj = y_pan;
//The following gets closer, but still allows too much pan in one direction
xPanAdj  = x_pan * (smaller / percentW);
yPanAdj  = y_pan * (smaller / percentH);

viewX = ((sourceW - viewW) / 2)  * (1 - xPanAdj);
viewY = ((sourceH - viewH) / 2)  * (1 - yPanAdj);

//Ideally we would never see this painful color...
gfx_set(1,0,0,opacity);

gfx_mode = 256;

//gfx_blit(input,aspect,x,y,w,h,srcx,srcy,srcw,srch);
gfx_blit(img1,asp,
   frameX, frameY, frameW|0, frameH|0,    //pipe-zero truncates any decimal
   viewX, viewY, viewW|0, viewH|0
   );
Thoughts?

Thanks as always to this great community!
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 01-11-2021, 10:55 AM   #2
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 5,646
Default

IDK if this will help, but it seems to work. Maybe you can draw some insight/inspiration.
https://forum.cockos.com/showthread.php?t=245490
ashcat_lt is online now   Reply With Quote
Old 01-14-2021, 12:17 PM   #3
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 606
Default

Looks like my script is already doing a lot of things automatically that this requires the user to do manually.... so I still prefer mine.

Even with this bug, the code is better than anything I've found...
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 01-14-2021, 12:47 PM   #4
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 5,646
Default

I never claimed that it was actually all of what you are trying to do. It actually doesn’t something else entirely, I think. It won’t pan past the edge of the frame in any direction, though, which is what I thought you wanted. The way I did it might not be the best and most efficient, but it certainly does work. I only hoped that part might give you a hint or something.
ashcat_lt is online now   Reply With Quote
Old 01-14-2021, 11:58 PM   #5
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 606
Default

Sorry, I didn't mean to sound dismissive...

I could definitely fix it by limiting, which looks like what you are doing... but I'd prefer to scale it.
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Reply

Thread Tools
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 -7. The time now is 05:18 PM.


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