function Deblock_QED ( clip clp, int "quant1", int "quant2", \ int "aOff1", int "bOff1", int "aOff2", int "bOff2", int "uv" ) { quant1 = default( quant1, 20 ) quant2 = default( quant2, 40 ) aOff1 = default( aOff1, quant1/2 ) # I've no clue if these are clever values or not! bOff1 = default( bOff1, quant1/4 ) # So: aOff2 = default( aOff2, quant1/4 ) # Also try all these 4 values @ 0 (zero), bOff2 = default( bOff2, quant1/8 ) # and quant1=30, quant2=40~45 instead. uv = default( uv, 1 ) # u=3 -> use proposed method for chroma deblocking # u=2 -> no chroma deblocking at all (fastest method) ox = clp.width() # u=1|-1 -> directly use chroma debl. from the normal|strong deblock() oy = clp.height() # With avisynth scripting, there is no information available about the position of the currently # processed pixel ... there simply is no such thing like an "actual" processed pixel. # So first I've to build up a grid covering the transitions between all 8x8 blocks, # and make some LUTmania with it later. Yes, this is cumbersome. block = blankclip(clp,width=6*4,height=6*4,color=$000000).addborders(4,4,4,4,color=$FFFFFF) block = stackhorizontal( block,block,block,block) block = stackvertical( block,block,block,block) .pointresize(32,32) .binarize(upper=false) block = stackhorizontal( block,block,block,block,block,block,block,block) block = stackvertical( block,block,block,block,block,block) block = stackhorizontal( block,block,block) block = stackvertical( block,block,block) block = block .crop(0,0,ox,oy) block = (uv!=3) ? block \ : YtoUV(block.crop(0,0,ox/2,oy/2),block.crop(0,0,ox/2,oy/2),block) block = block.trim(1,1) .loop(framecount(clp)) # create normal deblocking (for block borders) and strong deblocking (for block interiour) normal = clp.deblock(quant=quant1,aOffset=aOff1,bOffset=bOff1) strong = clp.deblock(quant=quant2,aOffset=aOff2,bOffset=bOff2) # build difference maps of both normalD = yv12lutxy(clp,normal,"x y - 128 +","x y - 128 +","x y - 128 +",U=uv,V=uv) strongD = yv12lutxy(clp,strong,"x y - 128 +","x y - 128 +","x y - 128 +",U=uv,V=uv) # separate border values of the difference maps, and set the interiours to '128' strongD2 = yv12lutxy(StrongD,block,"y 255 = x 128 ?","y 255 = x 128 ?","y 255 = x 128 ?",U=uv,V=uv) normalD2 = yv12lutxy(normalD,block,"y 255 = x 128 ?","y 255 = x 128 ?","y 255 = x 128 ?",U=uv,V=uv) # interpolate the border values over the whole block: DCTFilter can do it. (Kiss to Tom Barry!) # (Note: this is not fully accurate, but a reasonable approximation.) strongD3 = strongD2.yv12lut("x 128 - 1.01 * 128 +","x 128 - 1.01 * 128 +","x 128 - 1.01 * 128 +",U=uv,V=uv).dctfilter(1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0)# .yv12lut("x 128 - 2 / 128 +") # apply compensation from "normal" deblocking to the borders of the full-block-compensations calculated # from "strong" deblocking ... strongD4 = yv12lutxy(strongD3,normalD2,"y 128 = x y ?","y 128 = x y ?","y 128 = x y ?",U=uv,V=uv) # ... and apply it. deblocked= yv12lutxy(clp,strongD4,"x y 128 - -","x y 128 - -","x y 128 - -",U=uv,V=uv) # simple decisions how to treat chroma deblocked = (uv<0) ? deblocked.mergechroma(strong) : uv<2 ? deblocked.mergechroma(normal) : deblocked deblocked return( last ) }