Guest User

Deblock_QED_MT2

a guest
Jun 19th, 2016
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. # Changes 2008-08-18: (Didée)
  2. # - Replaced the ugly stackXXX cascade with mt_LutSpa() (requires MaskTools v2.0a35)
  3. # - Changed Quant and Offset defaults to 24,28,2,4,4,8
  4.  
  5. # Changes 2010-05-25:
  6. # - Explicitly specified parameters of mt_LutSpa()
  7. # (required due to position of new 'biased' parameter, starting from MaskTools 2.0a43)
  8. # - Non mod 16 input is now padded with borders internally
  9.  
  10. # Changes 2010-08-18:
  11. # - Replaced AddBorders with PointResize
  12. # - Changed Quant and Offset defaults to 18,19,3,4,1,1 to reduce blurring
  13.  
  14. # Changes 2010-10-16:
  15. # - Replaced 'relative' with the new 'mode' parameter in mt_LutSpa(), starting from MaskTools 2.0a45
  16. # - Changed Quant and Offset defaults to 24,26,1,1,2,2 to increase effectiveness, but still within sensible limits.
  17. # (see for details: http://forum.doom9.org/showthread.php?p=810932#post810932)
  18.  
  19. # Changes 2011-11-29: (06_taro)
  20. # - Replaced (chroma=uv>2?"process":"ignore") by (chroma=uv>2?"process":"copy") to avoid garbage clip when uv=2.
  21. # The formal parameter is not used by MaskTools2 any more, if ever used.
  22. # Foxyshadis once mentioned chroma="ignore" but I had never found a document containing it.
  23.  
  24. # Changes 2016-06-19: (A.SONY)
  25. # - re add "ignore" for chroma but if uv=2 will use "copy"
  26. # - add exdeblock1 and exdeblock2 to use an external deblock
  27.  
  28. function Deblock_QED ( clip clp, int "quant1", int "quant2",
  29. \ int "aOff1", int "bOff1", int "aOff2", int "bOff2", int "uv", string "exdeblock1", string "exdeblock2" )
  30. {
  31.  
  32. quant1 = default( quant1, 24 ) # Strength of block edge deblocking
  33. quant2 = default( quant2, 26 ) # Strength of block internal deblocking
  34.  
  35. aOff1 = default( aOff1, 1 ) # halfway "sensitivity" and halfway a strength modifier for borders
  36. aOff2 = default( aOff2, 1 ) # halfway "sensitivity" and halfway a strength modifier for block interiors
  37. bOff1 = default( bOff1, 2 ) # "sensitivity to detect blocking" for borders
  38. bOff2 = default( bOff2, 2 ) # "sensitivity to detect blocking" for block interiors
  39.  
  40. uv = default( uv, 3 ) # u=3 -> use proposed method for chroma deblocking
  41. # u=2 -> no chroma deblocking at all (just copy it from source)
  42. # u=1 -> ignore chroma (garbage but fastest method)
  43. # u=-1 -> directly use chroma debl. from the normal|strong deblock()
  44.  
  45. # add borders if clp is not mod 8
  46. padX = clp.width%8 == 0 ? 0 : (8 - clp.width%8)
  47. padY = clp.height%8 == 0 ? 0 : (8 - clp.height%8)
  48. clp=clp.pointresize(clp.width+padX, clp.height+padY, 0, 0, clp.width+padX, clp.height+padY)
  49.  
  50. # block
  51. block = clp.mt_LutSpa(mode="absolute",expr="x 1 + 8 % 1 < x 8 % 1 < y 1 + 8 % 1 < y 8 % 1 < | | | 255 0 ?",U=3,V=3)
  52.  
  53. # create normal deblocking (for block borders) and strong deblocking (for block interiour)
  54. normal = defined(exdeblock1) ? eval("clp." + exdeblock1) : clp.deblock(quant=quant1,aOffset=aOff1,bOffset=bOff1)
  55. strong = defined(exdeblock2) ? eval("clp." + exdeblock2) : clp.deblock(quant=quant2,aOffset=aOff2,bOffset=bOff2)
  56.  
  57. # build difference maps of both
  58. normalD = mt_makediff(clp,normal,chroma=uv>2?"process":uv==2?"copy":"ignore")
  59. strongD = mt_makediff(clp,strong,chroma=uv>2?"process":uv==2?"copy":"ignore")
  60.  
  61. # separate border values of the difference maps, and set the interiours to '128'
  62. normalD2 = mt_lutxy(normalD,block,expr="y 255 == x 128 ?",U=uv,V=uv)
  63. strongD2 = mt_lutxy(StrongD,block,expr="y 255 == x 128 ?",U=uv,V=uv)
  64.  
  65. # interpolate the border values over the whole block: DCTFilter can do it. (Kiss to Tom Barry!)
  66. # (Note: this is not fully accurate, but a reasonable approximation.)
  67. # add borders if clp is not mod 16
  68. sw=strongD2.width sh=strongD2.height
  69. remX = sw%16 == 0 ? 0 : (16 - sw%16)
  70. remY = sh%16 == 0 ? 0 : (16 - sh%16)
  71. strongD3 = strongD2.pointresize(sw+remX, sh+remY, 0, 0, sw+remX, sh+remY).mt_lut(expr="x 128 - 1.01 * 128 +",U=uv,V=uv)\
  72. .dctfilter(1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0).crop(0,0,-remX,-remY)
  73.  
  74. # apply compensation from "normal" deblocking to the borders of
  75. # the full-block-compensations calculated from "strong" deblocking ...
  76. strongD4 = mt_lutxy(strongD3,normalD2,expr="y 128 == x y ?",U=uv,V=uv)
  77.  
  78. # ... and apply it.
  79. deblocked= mt_makediff(clp,strongD4,chroma=uv>2?"process":uv==2?"copy":"ignore")
  80.  
  81. # simple decisions how to treat chroma
  82. deblocked = (uv<0) ? deblocked.mergechroma(strong) : uv<2 ? deblocked.mergechroma(normal) : deblocked
  83.  
  84. deblocked.crop(0,0,-padX,-padY) # remove mod 8 borders
  85. }
Advertisement
Add Comment
Please, Sign In to add comment