View Single Post
Old 11-15-2018, 09:37 AM   #17
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,737
Default

Here's a version that shifts down/right and up/left simultaneously, though at the cost of twice the CPU use:
Code:
// blur, YV12
//@param1:weight_parm 'blur amount' .5 0 .99 0.5 0.001
//@param2:bidir 'bidirectional' 1 0 1 0 1

in=0;

colorspace='YV12';
input_info(in,w,h);
gfx_img_resize(-1,w,h);

weight = weight_parm ^.25;
uvweight= sqr(weight);
code="
(_1 -= 1) < 0 ? (
  _1=eval_w*.5-1;
  _2=y1; _3=y3; _4=u; _5=v;
);
y1+=weight*(_2-y1); _2=(y2+=weight*(y1-y2));
y3+=weight*(_3-y3); _3=(y4+=weight*(y3-y4));
_4=(u+=uvweight*(_4-u));
_5=(v+=uvweight*(_5-v));
";

pass=0;
weight>.00001 ? loop(bidir?2:1,
  gfx_dest = rotWs2 = gfx_img_resize(rotWs2,w,h); 
  pass==0 ? gfx_blit(in,0,0,0,w,h,0,0,w,h)
        : gfx_deltablit(in,0,0,w,h,w-1,h-1,-1,0,0,-1);
  
  // convolve in x
  eval_w = w;
  gfx_evalrect(0,0,w,h, code);
  
  // rotate to expanded vertical work buffer 
  gfx_dest = rotWs1 = gfx_img_resize(rotWs1,h,w);
  gfx_deltablit(rotWs2,0,0,h,w, 0,0, 0,1,1,0,0,0);
   
  // convolve in y (now x)
  eval_w = h;
  gfx_evalrect(0,0,h,w, code);
  
  // rotate back to output framebuffer
  gfx_dest = -1;
  gfx_a=pass?0.5:1;
  pass==0? gfx_deltablit(rotWs1,0,0,w,h,0,0, 0,1,1,0,0,0):
    gfx_deltablit(rotWs1,0,0,w,h,h-1,w-1, 0,-1,-1,0,0,0);
  gfx_a=1;
  pass+=1;
) : gfx_blit(in);
(Edit: made it optional)

Last edited by Justin; 11-15-2018 at 01:26 PM.
Justin is offline   Reply With Quote