Advertisement
mawen1250

NRDB

Dec 31st, 2011
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function NRDB( clip   input,
  2.              \ string "dither",  bool   "d_lsb",   bool  "d_lsb_in",
  3.              \ int    "range",    int    "db_Y",    int   "db_Cb",
  4.              \ int    "db_Cr",   int    "ditherY", int   "ditherC",
  5.              \ bool   "dynamic_dither_noise",      bool  "keep_tv_range",
  6.              \ string "nr",      bool   "nr_lsb",  bool  "nr_lsb_in",
  7.              \ bool   "nr_Y",    bool   "nr_U",    bool  "nr_V",
  8.              \ float  "sigma",   float  "sigma2",
  9.              \ bool   "lsb",     bool   "lsb_in",
  10.              \ int    "ditherD", string "ditherCustom" )
  11. {  
  12.  
  13.   #-----------------------------------------------------------------------------------
  14.  
  15.   lsb_in   = Default( lsb_in,   false )  # Input clip is 16-bit stacked or not
  16.   lsb      = Default( lsb,      false )  # Output clip is 16-bit stacked or not
  17.  
  18.   src16    = lsb_in  ? input : input.Dither_convert_8_to_16()
  19.   src8     = !lsb_in ? input : input.DitherPost(mode=0, ampn=0)
  20.   last     = src8
  21.   res      = width * height
  22.  
  23.   ###### "dither"  : custom debanding method in string, "nop" for no processing
  24.   d_lsb     = Default( d_lsb,    false )  # custom debanding method outputs 16-bit stacked clip or not
  25.   d_lsb_in  = Default( d_lsb_in, false )  # custom debanding method accepts 16-bit stacked clip or not
  26.   ###### settings in f3kdb
  27.   range     = ( res <= 589824 ) ? Default( range, 9 ) :
  28.             \ ( res <= 921600 ) ? Default( range, 12 ) :
  29.             \                     Default( range, 15 )
  30.   db_Y      = Default( db_Y,     64    )
  31.   db_Cb     = Default( db_Cb,    0     )
  32.   db_Cr     = Default( db_Cr,    0     )
  33.   ditherY   = Default( ditherY,  0     )
  34.   ditherC   = Default( ditherC,  0     )
  35.   dynamic_dither_noise = Default( dynamic_dither_noise, false )
  36.   keep_tv_range = Default( keep_tv_range, false )
  37.   ######
  38.   ######
  39.  
  40.   ###### "nr"   : custom denoise method in string, "nop" for no processing
  41.   nr_lsb    = Default( nr_lsb,    false )  # custom grain generator outputs 16-bit stacked clip or not
  42.   nr_lsb_in = Default( nr_lsb_in, false )  # custom grain generator accepts 16-bit stacked clip or not
  43.   ###### settings in dfttest
  44.   nr_Y      = Default( nr_Y,      true  )  # whether to process Y plane in dfttest
  45.   nr_U      = Default( nr_U,      false )  # whether to process U plane in dfttest
  46.   nr_V      = Default( nr_V,      false )  # whether to process V plane in dfttest
  47.   sigma     = Default( sigma,     4.0   )  # sigma in dfttest
  48.   sigma2    = Default( sigma2,    4.0   )  # sigma2 in dfttest
  49.   ######
  50.   ######
  51.  
  52.   ditherD  = Default( ditherD,      0 )  # 16-bit to 8-bit dithering method when lsb=false, same as "mode" in DitherPost
  53.   ###### "ditherCustom" : custom dithering method in string, e.g., ditherCustom="DitherPost(mode=2)" gives same result as ditherD=2
  54.  
  55.  
  56.   #-----------------------------------------------------------------------------------
  57.  
  58.   nred = !Defined(nr) ? src8.dfttest( lsb=false, lsb_in=false, dither=0, Y=nr_Y, U=nr_U, V=nr_V, sigma=sigma, sigma2=sigma2 ).Dither_convert_8_to_16()
  59.   \                   : ( nr=="nop" || nr=="nop()" ) ? src16
  60.   \                                                  : nr_lsb_in ? nr_lsb ? Eval( "src16." + nr )
  61.   \                                                                       : Eval( "src16." + nr + ".Dither_convert_8_to_16()" )
  62.   \                                                              : nr_lsb ? Eval( "src8."  + nr )
  63.   \                                                                       : Eval( "src8."  + nr + ".Dither_convert_8_to_16()" )
  64.  
  65.   #-----------------------------------------------------------------------------------
  66.  
  67.   noise = mt_makediff( src16.Dither_get_msb, nred.Dither_get_msb, Y=3, U=3, V=3 )
  68.  
  69.   #-----------------------------------------------------------------------------------
  70.  
  71.   nred8 = nred.DitherPost(mode=0, ampn=0)
  72.   db    = !Defined(dither) ? nred.f3kdb(range=range, Y=db_Y, Cb=db_Cb, Cr=db_Cr,
  73.   \                                     ditherY=ditherY, ditherC=ditherC, sample_mode=2,
  74.   \                                     blur_first=true, dynamic_dither_noise=dynamic_dither_noise, precision_mode=3,
  75.   \                                     keep_tv_range=keep_tv_range, input_mode=1, output_mode=1 )
  76.   \                        : ( dither=="nop" || dither=="nop()" ) ? nred
  77.   \                                                               : d_lsb_in ? d_lsb ? Eval( "nred."   + dither )
  78.   \                                                                                  : Eval( "nred."   + dither + ".Dither_convert_8_to_16()" )
  79.   \                                                                          : d_lsb ? Eval( "nred8."  + dither )
  80.   \                                                                                  : Eval( "nred8."  + dither + ".Dither_convert_8_to_16()" )
  81.  
  82.   #-----------------------------------------------------------------------------------
  83.  
  84.   result16 = StackVertical( db.Dither_get_msb.mt_adddiff( noise ), db.Dither_get_lsb )
  85.   result   = lsb ? result16 : Defined(ditherCustom) ? Eval("result16."+ditherCustom) : result16.DitherPost(mode=ditherD)
  86.  
  87.   return result
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement