View Single Post
Old 11-15-2018, 08:49 PM   #23
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 11,865
Default

OK one more -- this one looks extra good, allows you to control the ratio between vertical and horizontal, allows you to turn off diff l/r/u/d blurs, but is also pretty slow.

Code:
// Blur
//@param1:weight_parm 'blur amount' .5 0 .99 0.5 0.001
//@param2:weight_mod 'Y modifier' 1 .8 1.2 1.0 0.001
//@param4:want_l 'leftward' 1 0 1 0 1
//@param5:want_r 'rightward' 1 0 1 0 1
//@param6:want_u 'upward' 1 0 1 0 1
//@param7:want_d 'downward' 1 0 1 0 1

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

function rot(new_ang, dest, blur) local(lw,lh,ang) (
  gfx_dest=dest;
  ang = (new_ang+4-c_ang)&3;
  c_ang = new_ang&3;
  lw=(c_ang&1) ? h:w;
  lh=(c_ang&1) ? w:h;
  ang==0 ? gfx_blit(c_last,0, 0,0,lw,lh,0,0,lw,lh) :
  ang==1 ? gfx_deltablit(c_last, 0,0, lw,lh, 0,   lw-1,  0, -1,  1,  0) :
  ang==2 ? gfx_deltablit(c_last, 0,0, lw,lh, lw-1,lh-1, -1,  0,  0, -1):
  ang==3 ? gfx_deltablit(c_last, 0,0, lw,lh, lh-1,0,     0,  1, -1,  0);    
  blur ? (     
    weight= min(weight_parm*((c_ang&1) ? weight_mod : 1/weight_mod),1) ^.25;
    uvweight=max(min(weight*5.2-3.7,.94),0); // experimentally derived
    eval_w = lw; gfx_evalrect(0,0,lw,lh, sprintf(#,"
      (_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));
      %s", uvweight > 0.000001 ? "
        _4=(u+=uvweight*(_4-u));
        _5=(v+=uvweight*(_5-v));
        " : "")
    ); 
  );
  c_last=dest; 
);

c_ang=0;
c_last=in; 
weight_parm>.00001? ( 
  want_l ? rot(2, -1, 1);
  want_d ? rot(3, img3 = gfx_img_resize(img3,h,w),1);  
  want_u ? rot(1, img2 = gfx_img_resize(img2,h,w),1);
  want_r || c_last==-1 ? rot(0, c_last==-1 ? (img1 = gfx_img_resize(img1,w,h)) : -1,want_r);
);
c_last != -1 ? rot(0, -1, 0);

Last edited by Justin; 11-15-2018 at 09:18 PM. Reason: tweaked the UV filtering coefficient some to look better (for one bit of test material anyway)
Justin is online now   Reply With Quote