Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Resharpen v0 "probably works" edition
- Very safe, usually weak sharpening based on the idea of contrasharpening
- Does a normal blind sharpening, and clamps it to the range of values between filtered and source clips
- So if your filtered luma plane has a Y8 value of 100, source is 120, and sharpened is 140, the output will be 120
- Or in math terms: hi = max(flt, src)
- lo = min(flt, src)
- sharp = min(hi, sharp)
- sharp = max(lo, sharp)
- return sharp
- PARAMETERS
- flt = Filtered clip, to sharpen
- src = Unfiltered clip, for limiting
- rad = Radius of sharpening. When mode="gauss" this is the amount of iterations of removegrain in the pattern 11, 20, 20...
- When mode="box" this is the radius of the box filtering (average blur)
- Default: 2 for HD, 1for SD (HD is anything with dimensions of 1100x600 or greater)
- mode = Type of blur used. "gauss" uses RemoveGrain to imitate a gaussian blur
- "box" uses RemoveGrain only if rad=1, otherwise it uses the rather outdated Dither_box_filter16 which requires stack16 (this is handled by the filter by checking the clip depth and lsb parameter)
- Default: "gauss"
- lsb = Does the same thing it always does.
- Default: False
- y/u/v = How to process each channel. 1 = trash, 2 = copy from flt, 3 = process, 4 = copy from src
- Default (y): 3
- Default (u): 2
- Default (v): Whatever you set "u" to
- DEPENENCIES
- - AVS+
- - RGTools
- - Dither (for mode="box" and lsb=True)
- - CLExpr (for lsb=True)
- */
- function resharpen(clip flt, clip src, int "rad", val "mode", bool "lsb", int "y", int "u", int "v"){
- rad = flt.Width < 1100 && flt.Height < 600 ? Default(rad, 1)
- \ : Default(rad, 2)
- mode = Default(mode, "gauss")
- lsb = Default(lsb, False)
- y = Default(y, 3)
- u = Default(u, 2)
- v = Default(v, u)
- blur = mode=="gauss" ? flt.resharpen_gauss(rad, lsb, y, u, v, True)
- \ : flt.resharpen_box(rad, lsb, y, u, v)
- yexp = y==3 ? "x x + z - x y min max x y max min" : y==2 ? "x" : y==4 ? "y" : "0"
- uexp = u==3 ? "x x + z - x y min max x y max min" : u==2 ? "x" : u==4 ? "y" : "range_half"
- vexp = v==3 ? "x x + z - x y min max x y max min" : v==2 ? "x" : v==4 ? "y" : "range_half"
- return lsb ? flt.cl_exprxyz(src, blur, yExpr=yexp, uExpr=uexp, vExpr=vexp, Y=y, U=u, V=v, lsb=True)
- \ : Expr(flt, src, blur, yexp, uexp, vexp)
- }
- function resharpen_gauss(clip src, int rad, bool lsb, int y, int u, int v, bool first){
- rgy = y==3 ? first ? 11 : 20 : -1
- rgu = u==3 ? first ? 11 : 20 : -1
- rgv = v==3 ? first ? 11 : 20 : -1
- return rad==0 ? src
- \ : lsb ? src.Dither_removegrain16(rgy, rgu, rgv).resharpen_gauss(rad-1, lsb, y, u, v, False)
- \ : src.RemoveGrain (rgy, rgu, rgv).resharpen_gauss(rad-1, lsb, y, u, v, False)
- }
- function resharpen_box(clip src, int rad, bool lsb, int y, int u, int v){
- rgy = y==3 ? 20 : -1
- rgu = u==3 ? 20 : -1
- rgv = v==3 ? 20 : -1
- bits = src.BitsPerComponent
- return rad == 1 ? lsb ? src.Dither_removegrain16(rgy, rgu, rgv)
- \ : src.RemoveGrain(rgy, rgu, rgv)
- \ : lsb ? src.Dither_box_filter16(rad, y=y, u=u, v=v)
- \ : bits==8 ? src.Dither_convert_8_to_16().Dither_box_filter16(rad, y=y, u=u, v=v).DitherPost(mode=-1, y=y, u=u, v=v)
- \ : bits==16 ? src.ConvertToStacked().Dither_box_filter16(rad, y=y, u=u, v=v).ConvertFromStacked()
- \ : src.ConvertBits(16).ConvertToStacked().Dither_box_filter16(rad, y=y, u=u, v=v).ConvertFromStacked().ConvertBits(bits)
- }
Add Comment
Please, Sign In to add comment