Download for Windows Download for Linux Download for FreeBSD Download for Mac Manual Wiki Forum IRC Trac

Sunday, July 20, 2008

Why rendering \k and \kf effects is fast in VSFilter

This is a repost of something I wrote earlier on the AnimeSuki forums, in relation to a discussion of how much CPU time various kinds of karaoke effects take to render.

This discussion only covers TextSub (VSFilter), I don't know what other renderers do and their use is still very limited. Also, everything that goes for \k also goes for \kf, \K and \ko. They use the same rendering technique.
This will also explain a funny "artifact" some karaokers might have seen when using \kf with vertical karaoke.

First, while TextSub does have a function that should tell whether a line is animated or not (presumably so it could avoid re-rendering static lines for every frame) that function is empty, it just says "return true;", so every line is always considered animated, no matter what's in it.

Next, the way \k effects are handled is using a "switchpoints" algorithm.
TextSub renders (up to) three different single-channel 6-bit bitmaps for each line, fill, border and shadow. (Border is Shadow minus Fill. Shadow is Fill "expanded" to give an outline.)
When the subtitle is to be painted onto the video, TextSub builds a list of switchpoints for each line component. A switchpoint has two parts: Colour (which includes alpha) and end-coordinate. The end-coordinate is which pixel index on the scanline the colour is valid up till.
(When a line has a vector-\clip, the vector drawing is rendered as a fourth 6-bit image which is used to mask the other layers while painting.)

When there is no \k effect, there is only one switchpoint for each component, which has the colour of it and the end-coordinate set to infinity (actually 0xFFFFFFFF).
When there is a \k effect, the current position of the highlight is calculated for the frame, and a switchpoint is added at the right coordinate. This is very fast to calculate. The pixel size of every syllable is already known (because the rasteriser breaks the line into "words" at every change in formatting - \k tags are formatting) and for \kf effects, getting the position within the syllable is a matter of simple linear interpolation between the endpoints of the syllable.

Now for painting an actual component.
For every scanline of the component, loop over each switchpoint. For each switchpoint, paint its colour to the video frame, using the component as mask and optionally also masking with a vector-\clip mask. When the endpoint of a switchpoint is reached, do the same for the next switchpoint, continuing where the previous one left off.
This is repeated for every scanline of the component. Also very fast.
(The case of just a single switchpoint, ie. no \k effect, is questionably optimised by removing the switchpoints-loop. I think this in practice only saves a few hundred or maybe thousand machine instructions in total for each component, but I haven't checked the actual code.)

For the reason why \k effects don't rotate when you use \frz (and family): They are scanline-based and the switchpoints are assumed to always be on the same coordinate on every scanline. The switchpoints can't change between scanlines for the same component.

This should explain why \k effects are fast to render, unlike many \t-based effects. Using purely \k-based karaoke effects is safe to do when softsubbing, any modern CPU should be able to render it, since it doesn't really take any more CPU than rendering static lines.

Related Posts by Categories



24 comments:

  1. I am really impressed by this blog. The document typing services are best to help your document so always try to use our services.

    ReplyDelete
  2. The article you have shared here very good. This is really interesting information for me. Thanks for sharing!
    hotmail.com login |hotmail login |gmail login

    ReplyDelete
  3. Facebook is a dazzling system which provides its individuals enormous probabilities to increase their perspectives. buy usa facebook likes

    ReplyDelete
  4. You will meet amazing and beautiful people that may be the same as you or complete different

    ReplyDelete
  5. I have learn some excellent stuff here. Definitely value bookmarking for revisiting. I surprise how so much effort you place to create any such wonderful informative website.
    To play the most fun games entrar aquí para comenzar a jugar for free.

    ReplyDelete
  6. Your blog is great. I read a lot of interesting things from it. Thank you very much for sharing. Hope you will update more news in the future.
    games for girls dress up

    ReplyDelete
  7. I would like to thank you for the efforts you have made in writing this article.
    fleeingthecomplexgame.com Warwings.net Flipmaster.co

    ReplyDelete
  8. If this was the kind of information that I would find on every page that I visit, it could be great. I love this kind of a post. You can always share more at all times. When looking for the most reliable and professional T-test assignment help, why not give us a call. We offer the most reliable assignment, which come at very affordable rates and on time.

    ReplyDelete
  9. I am convinced that your website is convinced that weblog is very new. Probably I am going to bookmark your site. There are certainly impressive stories. Passion for sharing your website with us.
    Regards - www.office.com/setup

    ReplyDelete

If you need help with Aegisub or have a bug report please use our forum instead of leaving a comment here. If you have a feature request, please go to our UserVoice page.

You will get better help on our forum than in the blog comments.