SHOW:
|
|
- or go back to the newest paste.
| 1 | - | # 2019.07.20 |
| 1 | + | # 2019.07.28 |
| 2 | function BalanceBorders(clip c, int cTop, int cBottom, int cLeft, int cRight, int "thresh", int "blur") | |
| 3 | {
| |
| 4 | sisavs26 = !(VersionNumber() < 2.6) | |
| 5 | sisphbd = AvsPlusVersionNumber > 2294 | |
| 6 | ||
| 7 | sislumaonly = sisphbd ? c.isy() : sisavs26 ? c.isy8() : false | |
| 8 | ||
| 9 | sisfullchrom = sisphbd ? c.is444() : sisavs26 ? c.isyv24() : false | |
| 10 | ||
| 11 | sis420chr = sisphbd ? c.is420() : c.isyv12() | |
| 12 | ||
| 13 | Assert(sis420chr || sisfullchrom || sislumaonly, "This is not a Square chroma clip.") | |
| 14 | ||
| 15 | thresh = Default(thresh, 128) | |
| 16 | blur = Default(blur, 999) | |
| 17 | ||
| 18 | Assert(blur > 0, "Blur parameter in BalanceBorders() must be > 0") | |
| 19 | Assert(thresh > 0, "Thresh parameter in BalanceBorders() must be > 0") | |
| 20 | ||
| 21 | c | |
| 22 | cTop >0 ? BalanceTopBorder(cTop, thresh, blur, sislumaonly, sis420chr, sisavs26).sTryFTurnRight() : last.sTryFTurnRight() | |
| 23 | cLeft >0 ? BalanceTopBorder(cLeft, thresh, blur, sislumaonly, sis420chr, sisavs26).sTryFTurnRight() : last.sTryFTurnRight() | |
| 24 | cBottom >0 ? BalanceTopBorder(cBottom, thresh, blur, sislumaonly, sis420chr, sisavs26).sTryFTurnRight() : last.sTryFTurnRight() | |
| 25 | cRight >0 ? BalanceTopBorder(cRight, thresh, blur, sislumaonly, sis420chr, sisavs26).sTryFTurnRight() : last.sTryFTurnRight() | |
| 26 | } | |
| 27 | ||
| 28 | function BalanceTopBorder(clip c, int cTop, int "thresh", int "blur", bool "sislumaonly", bool "sis420chr", bool "sisavs26") | |
| 29 | {
| |
| 30 | cWidth = c.width | |
| 31 | cHeight = c.height | |
| 32 | cTop = min(cTop,cHeight-1) | |
| 33 | cTop2 = max(sis420chr ? 4 : 2,cTop) | |
| 34 | blurWidth = max(4,floor(cWidth/blur)) | |
| 35 | ||
| 36 | c2 = c.PointResize(cWidth*2,cHeight*2) | |
| 37 | ||
| 38 | c2.\ | |
| 39 | Crop(0,cTop*2,cWidth*2,2) | |
| 40 | PointResize(cWidth*2,cTop2*2) | |
| 41 | BilinearResize(blurWidth*2,cTop2*2) | |
| 42 | mt_convolution("1 1 1","0 1 0",y=3,u=sislumaonly ? 1 : 3,v=sislumaonly ? 1 : 3)
| |
| 43 | PointResize(blurWidth*2,cTop*2) | |
| 44 | BilinearResize(cWidth*2,cTop*2) | |
| 45 | referenceBlur = last | |
| 46 | ||
| 47 | original = c2.Crop(0,0,cWidth*2,cTop*2) | |
| 48 | ||
| 49 | original | |
| 50 | PointResize(Width(),cTop2*2) | |
| 51 | BilinearResize(blurWidth*2,cTop2*2) | |
| 52 | mt_convolution("1 1 1","0 1 0",y=3,u=sislumaonly ? 1 : 3,v=sislumaonly ? 1 : 3)
| |
| 53 | PointResize(blurWidth*2,cTop*2) | |
| 54 | BilinearResize(cWidth*2,cTop*2) | |
| 55 | originalBlur = last | |
| 56 | ||
| 57 | balanced = sisavs26 ? mt_lutXYZ(original,originalBlur,referenceBlur,"z y - x +",clamp_float=true,use_expr=3,y=3,u=3,v=3) : mt_lutXYZ(original,originalBlur,referenceBlur,"z y - x +",y=3,u=3,v=3) | |
| 58 | difference = mt_makeDiff(balanced,original,y=3,u=3,v=3) | |
| 59 | ||
| 60 | tp = string(128+thresh) | |
| 61 | tm = string(128-thresh) | |
| 62 | difference = sisavs26 ? difference.mt_lut("x "+tp+" scalef > "+tp+" scalef x ?",Use_expr=2,y=3,u=3,v=3) : difference.mt_lut("x "+tp+" > "+tp+" x ?",y=3,u=3,v=3)
| |
| 63 | difference = sisavs26 ? difference.mt_lut("x "+tm+" scalef < "+tm+" scalef x ?",Use_expr=2,y=3,u=3,v=3) : difference.mt_lut("x "+tm+" < "+tm+" x ?",y=3,u=3,v=3)
| |
| 64 | ||
| 65 | mt_addDiff(original,difference,y=3,u=3,v=3) | |
| 66 | ||
| 67 | StackVertical(last,c2.Crop(0,cTop*2,cWidth*2,(cHeight-cTop)*2)).PointResize(cWidth,cHeight) | |
| 68 | } |