Old 07-02-2021, 06:22 PM   #1
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 690
Default Peephole/vignette with ajustable center

Hi everyone!

I really needed to have ajustable center coordinates for the peephole/vignette preset for one of my projects. I finally took the time to modify the code and here it is! I still have a minor rounding issue in the vignette function but it's very usable.



Code:
// vignette w/offset
//@param 1:size 'size' 1 0 2 1 0.01
//@param 2:scale 'shaping' 1 .5 10 5.25 0.1
//@param 3:div 'sub-divide' 32 8 64 36 1

//@param 5:wet 'outside alpha' 1.0 0 1 0.5 0.01
//@param 6:in1 'inside input' 0 -1 5 2 1
//@param 7:in2 'outside input' 1 -1 5 2 1

//@param 9:xoff 'x offset' 0 -1 1 0.01 0.001
//@param 10:yoff 'y offset' 0 -1 1 0.01 0.001

function mapin(x) ( x<0?-2:x>0?input_track(x-1) );
function vignette(x,y,w,h sz, adj, alpha)
  local(divw, divh, xp, yp, dx, dy, p, yv,xsc, ysc, xr, yr, mask)
  global(fs,div,fsw,fsh,project_w,project_h,colorspace)
(
  mask = colorspace=='RGBA'?-1:-2;
  divw = w*.5; while (divw > div) ( divw *= 0.5 ); divw |= 0;
  divh = h*.5; while (divh > div) ( divh *= 0.5 ); divh |= 0;

  dx = w / (divw-1); dy = h / (divh-1);
  xsc = fsw / project_w; ysc = fsh / project_h;
  yp=p=0;
  loop(divh,
    xp=0;
    yr = (yp+0.5)&mask;
    yv = sqr(yr-h*.5);
    loop(divw,
      xr = (xp+0.5)&mask;
      p[0]=(x + xr)*xsc; p[1] = (y + yr)*ysc;
      p[2] = alpha * max(min((sqrt(sqr(xr-w*.5)+yv)-sz)*adj,1),0);
      p += 3;
      xp += dx;
    );
    yp += dy;
  );

  gfx_xformblit(fs,x,y,w,h,divw,divh,0,1);
);

function copyr(x,y,w,h) global(project_w,project_h,fsw,fsh,fs,fstmp)
(
  fs===fstmp && fstmp ? gfx_fillrect(x,y,w,h)
   : gfx_blit(fs,0,x,y,w,h, x*fsw/project_w,y*fsh/project_h,w*fsw/project_w,h*fsh/project_h);
);

(insrc=mapin(in1)) || size<2 ? (
  input_info(insrc,srcw,srch);
  xoff = floor(xoff*srcw/2+0.5);
  yoff = floor(yoff*srch/2+0.5);
  (fs=mapin(in2)) < 0 || !input_info(fs,fsw,fsh) ? (
    fs = fstmp = gfx_img_resize(fstmp,fsw=2,fsh=2,1);
    srcw > 0 ? ( project_w=srcw; project_h=srch; ); // special case: if single source, size to that
  ) : srcw == 0 ? ( project_w=fsw; project_h=fsh; );

  sz = max(min(project_w,project_h)*size*.5,1);
  wet < 1 || sz>4 ? gfx_blit(insrc);

  size < 2 ? (
    maxrad = sz + sz/scale;
    xred = max(project_w*.5 - maxrad,0)&-2;
    yred = max(project_h*.5 - maxrad,0)&-2;
    gfx_a=wet;
    sz > 4 && size<2 ? (
      
      xred>0 ? (
        (xred+xoff)>0 ? copyr(0,0,xred+xoff,project_h);
        copyr(project_w-xred+xoff-1,0,xred-xoff,project_h);
      ); 
      yred>0?(
        copyr(xred+xoff,0,project_w-xred*2,yred+yoff);
        copyr(xred+xoff,project_h-yred+yoff-1,project_w-xred*2,yred-yoff);
      );
      
      gfx_mode = 0x40000; // extra clamping (prevent overflow in certain instanceS)
      vignette(xred+xoff,yred+yoff,project_w-xred*2,project_h-yred*2, sz, scale/sz, wet);
    ) : copyr(0,0,project_w,project_h);
  );
);

Last edited by papagirafe; 07-09-2021 at 10:12 AM. Reason: giving image public access
papagirafe is offline   Reply With Quote
Old 07-09-2021, 12:36 PM   #2
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
Default

Many thanks, papagirafe.
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
Eliseat is offline   Reply With Quote
Old 07-10-2021, 12:10 PM   #3
fuzzball
Human being with feelings
 
fuzzball's Avatar
 
Join Date: Dec 2020
Posts: 214
Default

I'm noticing that there is some "interaction" between the circular display and the edge-most pixels of the screen. See in this video along the very bottom left edge of the video. It's most apparent starting at about 8 seconds into this video.

https://www.youtube.com/watch?v=8lBQeMLTcN8

You'll probably need to full screen because the effect is only 1 pixel wide as far as I can tell.

It was also happening along the left side before I moved the circle a little to the right.
fuzzball is offline   Reply With Quote
Old 07-10-2021, 06:17 PM   #4
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 690
Default

I'm glad to hear that my little mod is useful for other productions! Yes, as I mentioned in my initial post, there seems to rounding issues in the sub function "vignette" that causes a few graphical artifacts. For lack of time to fully understand how the sub function works, I kept the original stock code which behave strangely in some cases where the inner circle (limit of the alpha transition) goes beyond the edge of the screen. The one pixel problem is often corrected by changing either the coordinates, the size or the shaping by the smallest increment (ctrl key).

Unfortunately a fix will have to wait until my production schedule clear a bit!
papagirafe is offline   Reply With Quote
Old 07-13-2021, 04:21 AM   #5
Finow79
Human being with feelings
 
Finow79's Avatar
 
Join Date: Mar 2018
Location: D
Posts: 154
Default

Useful!
Outside dim - cool!
Possible to change the shape- maybe to a rectangle?
Finow79 is offline   Reply With Quote
Old 07-13-2021, 04:58 AM   #6
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 690
Default

Quote:
Originally Posted by Finow79 View Post
Useful!
Outside dim - cool!
Possible to change the shape- maybe to a rectangle?
I am planning on making one like that too. In the mean time you can achieve the result you are looking applying 2 horizontal wipes + 2 vertical wipes on video item itself.
papagirafe 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 10:48 PM.


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