Advertisement
nanogyth

Untitled

Nov 30th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ng_sub(
  2. \   clip clp,
  3. \ string "text",
  4. \    int "first_frame",
  5. \    int "last_frame",
  6. \    int "text_color",
  7. \    int "halo_color",
  8. \    int "x",
  9. \    int "y",
  10. \ string "font",
  11. \    int "size",
  12. \    int "align",
  13. \    int "lsp",
  14. \    int "font_width",
  15. \    int "halo_width",
  16. \    int "halo_height",
  17. \    int "x_scale",
  18. \    int "y_scale",
  19. \    int "text_color8",
  20. \    int "halo_color8",
  21. \    int "font8",
  22. \    int "spc8",
  23. \    int "lsp8",
  24. \    int "align8",
  25. \    int "x8",
  26. \    int "y8",
  27. \    int "size8",
  28. \    int "font_width8",
  29. \    int "font_angle8",
  30. \ string "halo8",
  31. \ string "shadow8"
  32. \){
  33.  
  34. #Version 3 2012/12/1
  35.  
  36.     text = default( text, "This is a tool-assisted recording.\n" + \
  37.                           "For details, visit http://TASVideos.org/")
  38.     first_frame = default(first_frame, 0)
  39.     last_frame  = default( last_frame, first_frame + 299)
  40.     text_color  = default( text_color, $00DDDDDD)
  41.     halo_color  = default( halo_color, $80000000)
  42.     font        = default(       font, "helvB12")
  43.     font_real   = "C:/mf/NGcode/TASEncodingPackage/fonts/"+ font +".bdf"
  44.     lsp         = default(        lsp, 0)
  45.     x_scale     = default(    x_scale, 8)
  46.     y_scale     = default(    y_scale, x_scale)
  47.     align       = default(      align, 8)
  48.     align_x = align % 3
  49.     align_y = (align - 1) / 3
  50.     default_x = (align_x == 0) ? clp.width - 8 : \
  51.                 (align_x == 2) ? clp.width / 2 : 8
  52.     default_y = (align_y == 0) ? clp.height - 8 : \
  53.                 (align_y == 1) ? clp.height / 2 : 8
  54.     x8 = (defined(x)) ? default(x8, x*x_scale) : default_x
  55.     y8 = (defined(y)) ? default(y8, y*y_scale) : default_y
  56.     x           = default(          x, default_x)
  57.     y           = default(          y, default_y)
  58.     size        = default(       size, 1)
  59.     font_width  = default( font_width, size)
  60.     halo_width  = default( halo_width, font_width)
  61.     halo_height = default(halo_height, size)
  62.  
  63.     text_color8 = default(text_color8, text_color)
  64.     halo_color8 = default(halo_color8, halo_color)
  65.     font8       = default(      font8, "Ariel")
  66.     spc8        = default(       spc8, 0)
  67.     lsp8        = default(       lsp8, lsp*y_scale)
  68.     align8      = default(     align8, align)
  69.     size8       = default(      size8, 112)
  70.     font_width8 = default(font_width8, 0)
  71.     font_angle8 = default(font_angle8, 0)
  72.     halo_radius8 = 0
  73.     mode8        = ""
  74.    
  75. #OO@
  76. #   OO@
  77. #      O@
  78. #        @
  79. #         @
  80. #          @
  81. #          O
  82. #           @
  83. #           O
  84. #           O
  85. #            @
  86. #            O
  87. #@           O
  88.  
  89. #using an unfilled circle reduces the number of calculations
  90. #by a factor of ~16
  91.     circle_12_jagged="0 0 "+\
  92.         "  2 12   5 11   7 10   8 9 "+\
  93.         "  12 2   11 5   10 7   9 8 "+\
  94.         " -2 12  -5 11  -7 10  -8 9 "+\
  95.         " -12 2  -11 5  -10 7  -9 8 "+\
  96.         "-2 -12 -5 -11 -7 -10 -8 -9 "+\
  97.         "-12 -2 -11 -5 -10 -7 -9 -8 "+\
  98.         " 2 -12  5 -11  7 -10  8 -9 "+\
  99.         " 12 -2  11 -5  10 -7  9 -8 "
  100.  
  101. circle_12="0 0 "+\
  102. "12 0 0 12 -12 0 0 -12 "+\
  103. "1 12 2 12 3 11 4 11 5 11 6 10 7 10 8 9 "+\
  104. "12 1 12 2 11 3 11 4 11 5 10 6 10 7 9 8 "+\
  105. "-1 12 -2 12 -3 11 -4 11 -5 11 -6 10 -7 10 -8 9 "+\
  106. "-12 1 -12 2 -11 3 -11 4 -11 5 -10 6 -10 7 -9 8 "+\
  107. "-1 -12 -2 -12 -3 -11 -4 -11 -5 -11 -6 -10 -7 -10 -8 -9 "+\
  108. "-12 -1 -12 -2 -11 -3 -11 -4 -11 -5 -10 -6 -10 -7 -9 -8 "+\
  109. "1 -12  2 -12 3 -11 4 -11 5 -11 6 -10 7 -10 8 -9 "+\
  110. "12 -1  12 -2 11 -3 11 -4 11 -5 10 -6 10 -7 9 -8 "
  111.  
  112.     halo8        = default(          halo8, circle_12)
  113.     shadow8      = default(        shadow8, " -4 -8")
  114.  
  115.     sub = FreeSub(clp, text, x, y, first_frame, last_frame, \
  116.         font_real, size, text_color, halo_color, align, lsp, \
  117.         font_width, halo_width, halo_height)
  118.  
  119.     sub_HD = ng_bighalo(clp, text, x8, y8, first_frame, last_frame, \
  120.         font8, size8, text_color8, halo_color8, align8, spc8, lsp8, \
  121.         font_width8, font_angle8, halo_radius8, mode8, halo8, shadow8)
  122.        
  123.     (clp.height >= 1080) ? sub_HD : sub
  124. }
  125.  
  126. function ng_bighalo(
  127. \   clip clp,
  128. \ string text,
  129. \  float "x",
  130. \  float "y",
  131. \    int "first_frame",
  132. \    int "last_frame",
  133. \ string "font",
  134. \  float "size",
  135. \    int "text_color",
  136. \    int "halo_color",
  137. \    int "align",
  138. \    int "spc",
  139. \    int "lsp",
  140. \  float "font_width",
  141. \  float "font_angle",
  142. \    int "halo_radius",
  143. \ string "mode",
  144. \ string "halo",
  145. \ string "shadow"
  146. \){
  147.  
  148. #Version 15 2012/11/30
  149. # - drop shadow added
  150. # - halo_radius still works, but calculating the points of
  151. #   a hollow circle for halo is much faster
  152. # - mode is depricated since memo-ing isn't as needed
  153.  
  154.     first_frame = default(first_frame, 0)
  155.     last_frame  = default( last_frame, first_frame + 299)
  156.     font        = default(       font, "Ariel")
  157.     size        = default(       size, 112)
  158.     x           = default(          x, -1)
  159.     y           = default(          y, -1)
  160.     text_color  = default( text_color, $00DDDDDD)
  161.     halo_color  = default( halo_color, $80000000)
  162.     align       = default(      align, 5)
  163.     spc         = default(        spc, 0)
  164.     lsp         = default(        lsp, 0)
  165.     font_width  = default( font_width, 0)
  166.     font_angle  = default( font_angle, 0)
  167.     halo_radius = default(halo_radius, 12)
  168.     mode        = default(       mode, "depricated")
  169.     halo        = default(       halo, mt_circle(halo_radius))
  170.     shadow      = default(     shadow, " -4 -8")
  171.     w           = clp.width
  172.     h           = clp.height
  173.  
  174.     invis = BlankClip(1, w, h, pixel_type="YV12")
  175.     tm = Subtitle(invis, text, x, y, 0, 0, font, size, $00FFFFFF,\
  176.         0, align, spc, lsp, font_width, font_angle)
  177.     text_mask = tm.mt_expand(mode="0 0 "+shadow, chroma="-128")
  178.     halo_mask = text_mask.mt_expand(mode=halo, chroma="-128")
  179.    
  180.     h_color = BitAND(halo_color, $00FFFFFF)
  181.     t_color = BitAND(text_color, $00FFFFFF)
  182.     h_alpha = 255 - BitRShiftU(BitAND(halo_color, $FF000000), 24)
  183.     t_alpha = 255 - BitRShiftU(BitAND(text_color, $FF000000), 24)
  184.     lut_str = string(h_alpha)+ " x * 255 / " +string(t_alpha)+\
  185.               " " +string(h_alpha)+ " - y * 255 / +"
  186.  
  187.     alpha_mask = mt_lutxy(halo_mask, text_mask, lut_str)
  188.  
  189.     hc = BlankClip(1, w, h, color=h_color)
  190.     tc = Subtitle(hc, text, x, y, 0, 0, font, size, t_color,\
  191.         0, align, spc, lsp, font_width, font_angle)
  192.     overlay = tc.Mask(alpha_mask.ConvertToRGB32())
  193.    
  194.     clp.ApplyRange(first_frame, last_frame, "Layer", overlay)
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement