SHOW:
|
|
- or go back to the newest paste.
| 1 | ############################### | |
| 2 | # FastLineDarken 1.42x MT MOD # | |
| 3 | ############################### | |
| 4 | # | |
| 5 | # Written by Vectrangle (http://forum.doom9.org/showthread.php?t=82125) | |
| 6 | # Didée: - Speed Boost, Updated: 11th May 2007 | |
| 7 | # Dogway - added protection option. 12-May-2011 | |
| 8 | # A.SONY - added high bit support and others. 27-Mar-2017 | |
| 9 | # | |
| 10 | - | # * requires mt_masktools v2 |
| 10 | + | # * requires mt_masktools v2 in avs2.5 and masktools 2.2.5 in avs 2.6 or avs+ |
| 11 | # * requires yuv input | |
| 12 | # | |
| 13 | # | |
| 14 | # | |
| 15 | # Parameters are: | |
| 16 | # strength (integer) - Line darkening amount, 0-256. Default 48. Represents the _maximum_ amount | |
| 17 | # that the luma will be reduced by, weaker lines will be reduced by | |
| 18 | # proportionately less. | |
| 19 | # prot (integer) - Prevents the darkest lines from being darkened. Protection acts as a threshold. | |
| 20 | # Values range from 0 (no prot) to ~50 (protect everything). Default 5. | |
| 21 | # luma_cap (integer) - value from 0 (black) to 255 (white), used to stop the darkening | |
| 22 | # determination from being 'blinded' by bright pixels, and to stop grey | |
| 23 | # lines on white backgrounds being darkened. Any pixels brighter than | |
| 24 | # luma_cap are treated as only being as bright as luma_cap. Lowering | |
| 25 | # luma_cap tends to reduce line darkening. 255 disables capping. Default 191. | |
| 26 | # threshold (integer) - any pixels that were going to be darkened by an amount less than | |
| 27 | # threshold will not be touched. setting this to 0 will disable it, setting | |
| 28 | # it to 4 (default) is recommended, since often a lot of random pixels are | |
| 29 | # marked for very slight darkening and a threshold of about 4 should fix | |
| 30 | # them. Note if you set threshold too high, some lines will not be darkened | |
| 31 | # thinning (integer) - optional line thinning amount, 0-256. Setting this to 0 will disable it, | |
| 32 | # which is gives a _big_ speed increase. Note that thinning the lines will | |
| 33 | # inherently darken the remaining pixels in each line a little. Default 0. | |
| 34 | # | |
| 35 | # Changelog: | |
| 36 | # 1.42 - added high bit support in avs+ and others Optmized | |
| 37 | # 1.4 - added protection option. Prevents darkest lines to be over darkened thus creating artifacts (i.e. aliasing, clipping...) | |
| 38 | # - Optmized the code as suggested by Didée for possible faster processing. It also deals with the green screen bug. | |
| 39 | # 1.3 - added ability to thin lines, now runs much slower unless thinning=0. Changed the defaults (again) | |
| 40 | # 1.2 - huge speed increase using yv12lutxy =) | |
| 41 | # - weird darkening issues gone (they were caused by yv12layer) | |
| 42 | # - show option no longer available due to optimizations. Use subtract() instead | |
| 43 | # 1.1 - added luma_cap option | |
| 44 | # 1.0 - initial release | |
| 45 | # | |
| 46 | ||
| 47 | ||
| 48 | function FastLineDarkenMOD4( clip input, float "strength", float "prot", float "luma_cap", float "threshold", float "thinning") | |
| 49 | {
| |
| 50 | ## parameters ## | |
| 51 | str = string(default(strength, 48) /128.) | |
| 52 | lum = string(default(luma_cap, 191)) | |
| 53 | protection = default(prot,5) | |
| 54 | thr = string(default(threshold, 4)) | |
| 55 | thinning = default(thinning,0) | |
| 56 | thn = string(thinning /16.) | |
| 57 | ||
| 58 | Assert(!(input.isrgb()), "FastLineDarkenMOD4: RGB Color formats is not supported" ) | |
| 59 | ||
| 60 | ssispmt = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0 | |
| 61 | ||
| 62 | sislumaonly = ssispmt ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8() | |
| 63 | ||
| 64 | c = sislumaonly ? input : ssispmt ? input.converttoy() : input.converttoy8() | |
| 65 | ||
| 66 | ## filtering ## | |
| 67 | exin = c.mt_expand(thy=255/(protection+1)).mt_inpand() | |
| 68 | diff = VersionNumber() < 2.6 ? mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x") | |
| 69 | \ : mt_lutxy(c,exin,yexpr="y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? 127 scalef +") | |
| 70 | linemask= thinning != 0 ? VersionNumber() < 2.6 ? mt_lut(diff.mt_inpand(),"x 127 - "+thn+" * 255 +").RemoveGrain(20,-1) | |
| 71 | \ : mt_lut(diff.mt_inpand(),"clamp_f_i8 x 127 scalef - "+thn+" * range_max +").RemoveGrain(20,-1) : nop() | |
| 72 | thick = VersionNumber() < 2.6 ? mt_lutxy(c, exin, yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? "+str+" * x +",uexpr="x",vexpr="x",u=2, v=2) | |
| 73 | \ : mt_lutxy(c, exin, yexpr="clamp_f_i8 y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? "+str+" * x +",u=2, v=2) | |
| 74 | thin = thinning != 0 ? VersionNumber() < 2.6 ? mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 - "+str+" 1 + * +",u=2, v=2) | |
| 75 | \ : mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="clamp_f_i8 x y 127 scalef - "+str+" 1 + * +",u=2, v=2) : nop() | |
| 76 | ||
| 77 | thinning == 0 ? thick : mt_merge(thin,thick,linemask,y=3,u=2,v=2) | |
| 78 | ||
| 79 | return sislumaonly ? last : ssispmt ? CombinePlanes(last,input,planes="YUV",sample_clip=input) : ytouv(input.utoy8(),input.vtoy8(),last) | |
| 80 | } |