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

Friday, July 25, 2008

How VSFilter renders border and shadow

If you've ever used the \be or the new \blur tag you might wonder, why do they blur edges and not everything?

Example of how VSFilter blurs just edges and not everything
The answer lies in how VSFilter internally handles fill, border and shadow, and the relationship between them.


The basic component of a subtitle rendering is the fill. The fill is the main shape of the text, ie. what you see if you disable border and shadow. (When I write "text" here it can just as well be a vector drawing made with \p1.)

I am keeping things simple here, there are some technical details in the actual implementation I'm skipping over because they aren't relevant for the discussion, although they actually impact the actual algorithm used greatly. I might discuss the detailed algorithm later.

When I talk about bitmaps in this post, they are single-channel bitmaps, ie. black/white bitmaps. Colour is applied during the painting-step, this is described in detail below.

When a subtitle is to be rendered, VSFilter first creates a bitmap of the text fill. It then sees if the text should have a "wide outline", ie. if a \bord tag is in effect. If there is a wide outline, it allocates an additional bitmap that will contain the widened region.

The widened region is the fill bitmap modified in a way so it's effectively "embolded", ie. the outline is expanded outwards, but the entire fill is still kept.

Visualisation of how the widened region is the fill expanded outwards by border size
You might notice that the widened region looks a lot like the shadow. This is entirely correct, because it is used for rendering not just the border but also the shadow.

When the line is to be rendered, the fill bitmap is used as-is for fill, the widened region is used as-is for shadow, and the border is generated by subtracting the fill from the widened region, ie. the border is the part of the widened region that is not also in the fill.

Things work a little different when there is no border. In that case, the fill is painted as-is, but the shadow is also painted using the fill.

I wrote above that the fill and widened region bitmaps are black/white bitmaps, so what about colour? The bitmaps are simply re-coloured with the selcted colour during painting, or more correctly, used as alpha masks to paint a frame full of the colour.

Okay, so on to the blur effects.

The blur effects are applied to the bitmaps, either to the fill or to the widened region bitmap. If there is a widened region bitmap, it is applied to that one only and the fill is left alone. If there is no widened region (ie. no border) the blur is applied to only the fill bitmap.

This is why only the border blurs when you use \be or \blur along with a border, and why the fill does blur when you use blur on lines with no border: The fill bitmap is rendered on top of the blurred border, even though the border blur extends below the fill.

Related Posts by Categories



51 comments:

  1. Another enjoyable article!

    I guess the blurring employed by VSFilter runs a weighted kernel across the bitmap. Does it use a source and clone bitmap for this or just the source? The results can be quite different. What size kernel is used? 3x3? 5x5? Or does this depend on the user-selected depth? In other words, if it uses a 3x3 kernel (blur = 1) and the user wants a blur depth of 2, does it run the 3x3 code twice or increase the size of the kernel to 5x5? Is the blur process split into two passes (vertical and horizontal) to increase rendering speed? And is true Gaussian blurring used or just an approximation?

    Sorry for all the questions! I find this stuff fascinating, having knocked myself out for 24 months adding a pseudo-Gaussian blur to our app's bitmap subtitles. And I'm still not happy with the results! (http://www.spotsoftware.nl/bitmap.html) :)

    ReplyDelete
  2. Heh, late reply (somehow hadn't noticed this comment before) but here's an answer anyway.

    The \be tag uses a simple 3x3 matrix, [ 1 2 1; 2 4 2; 1 2 1 ]. It is not applied in a separated manner but just as a 3x3 convolution.

    With the "extended \be" patch you can give a larger parameter than 1 to \be, this causes the convolution to be applied that number of times. As the image in the main post shows, the results aren't very pretty.

    The \blur tag uses a real gaussian kernel applied as a separated filter. It is an approximated kernel, the elements are unsigned bytes ie. 0-255 range, and rather than being of infinite length it uses a cutoff which should be large enough to get the significant part of it.

    ReplyDelete
  3. I put {\be10} in my video, and i when i encode it with x264 it doesnt show :( What is the problem? I also use K-Lite codec pack. Can someone please help me out?

    ReplyDelete
  4. Please ask your support question in the forums, not in a blog comment.

    ReplyDelete
  5. This is what I have been searching in many websites and I finally found it here. Amazing article. I am so impressed. Could never think of such a thing is possible with it...I think you have a great knowledge especially while dealings with such subjects.

    ReplyDelete
  6. The outline which expanded towards the essaymania.net is used for retendering about their services.

    ReplyDelete
  7. Things work a little different when there is no border. In that case, the fill is painted as-is, but the shadow is also painted using the psy d dissertation.

    ReplyDelete
  8. from the website here you can easily access facebook account of other with getting the password from the link here.

    ReplyDelete
  9. I have been seeking in numerous sites and I at long last discovered it here. Astonishing article. I am so awed.paid facebook followers

    ReplyDelete
  10. This is great information for students. This article is very helpful i really like this blog thanks. facebook usa likes

    ReplyDelete
  11. This is really good information I have visited this blog to read something fresh and I really admire you efforts in doing so. buy targeted facebook likes

    ReplyDelete
  12. First You got a great blog.I will be interested in more similar topics.
    Signature:
    happy wheels
    friv
    girlsgogames
    games2girls
    happy wheels

    ReplyDelete
  13. Thanks for sharing this nice article. and i wish to again on your new blog keep sharing with your article.
    Thanks For Share....

    ReplyDelete
  14. Great writing it is such a good and nice idea thanks for sharing your article .I like your post.
    Thanks.....

    ReplyDelete
  15. Hello, thanks for taking the time to view my profile. I am an academic writer from the US who enjoys finding new topics to research and write about.
    Assignment writing Help

    ReplyDelete
  16. I was working and suddenly I visits your site frequently and recommended it to me to read also. Age Of War 2
    Big Farm | Slitherio
    Tank Trouble | Happy Wheels
    Goodgeme Empire | Slither.io

    ReplyDelete
  17. Love your blog!! Why don't you blog anymore :( I miss your blog. Wahhh
    watergirl and fireboy
    Geometry Dash

    ReplyDelete
  18. I very much agree with your comments. Your article is great. It helps me to know many things that previously I did not pay any attention to. Ask permission to share:
    Run 2 game - Run 2 unblocked - Run 2 game

    ReplyDelete
  19. Thank you for visiting our site. Sure you will feel is amazing. Since we have been very selective as many games and you can play online for free
    gun mayhem 3 | tank trouble 3
    learn to fly 3 | happywheels
    tank trouble |

    ReplyDelete
  20. Facebook has become a part of my life, not only helped me to connect with you but also where I can share every moment in life. I really like the convenience that it brings
    facebook baixar , baixar facebook , facebook baixar , baixar facebook , facebook baixar , baixar facebook gratis

    ReplyDelete
  21. The article gives me a lot of interesting information. I still often share life experiences with friends. And I enjoyed the convenience and attractiveness of free messaging app
    whatsapp baixar , baixar whatsapp , whatsapp baixar , baixar whatsapp gratis

    ReplyDelete
  22. Great information I will tweet to my friends to get them to check it out. keep it up. Thanks for sharing!.If have a long time than visit to:
    crosswords puzzles | dream league soccer apk | cookie clicker | dream league soccer apk | crossword puzzles | cookie clicker

    ReplyDelete
  23. After a decisive Gold Medal-winning game over Serbia, Nike Basketball commemorates the achievement with a KD 9, Kyrie 2, Curry 3 USA and Lebron Soldier 10.Each sneaker’s theme within the pack is simple, a touch of Kobe 10 gold mixed with other colors. Both the Kyrie and KD models feature red to Curry 3 Dub Nation match the USA jerseys, while the former features a black upper and an icy Kobe 6 blue sole. The LeBron Soldier 10 not only matches the golden sneaker trend to LeBron 10 a tee with white and gold throughout, the shoe actually looks like one of Jordan Basketball Shoes the PEs that LeBron James wore in the NBA Finals.You can pick up either kobe bryant shoes the KD 9, Kyrie 2, or LeBron Soldier 10 in the Nike Basketball Gold James Harden Shoes Medal Pack at the links below each picture:
    Jordan Brand celebrates Kobe Bryant’s first Kobe Bryant Shoes year out of the NBA with a special edition Air Jordan 9 Kobe release.Dressed Kyrie 2 in a White, Concord and Tour Yellow color scheme. This Air Jordan 9 is Cavalier Steam Shop a nod to Kobe’s original Air Jordan 9 PE in the Los Angeles Lakers Derrick Rose Shoes home colors. Featuring a White leather upper with Concord patent leather overlay and Yellow Kobe Venomenon 4 accents. A number “23” replaces the original Kobe number “8” on the heels.Look for Kobe 8 the Air Jordan 9 “Kobe” to release on November 19th, 2016 at select Jordan KD 6 Brand retail stores. The retail price tag is set at $190 USD.
    Following a

    ReplyDelete
  24. Great article, I was very impressed about it, wish you would have stayed next share
    strikeforce kitty 2 | red ball 4 | strike force kitty | red ball 3 | ninjago games

    ReplyDelete
  25. Life becomes more interesting and wonderful when you share your memorable moments with friends and family through unique photographs. You can create your own unique style impressed with image editing software. And after hours of work stress you can also

    tank trouble, tank trouble 2, tank trouble games, tank trouble

    ReplyDelete
  26. Life becomes more interesting and wonderful when you share your memorable moments with friends and family through unique photographs. You can create your own unique style impressed with image editing software. And after hours of work stress you can also
    dr driving, dr driving baixar ,download dr driving, dr driving

    ReplyDelete
  27. You need to have time to take care of the active. It in fact was a amusement account it. Look advanced to far added agreeable from you.

    banana kong download , banana kong , baixar banana kong , download banana kong , banana kong baixar

    ReplyDelete
  28. Mostly people have all the same things when they are writing academic task or any other writing, especially light music most people like during the writing.

    subway surf , baixar subway surf, subway surf download , download subway surf

    ReplyDelete
  29. Thanks I have read your article, it is very interesting and exciting
    download go launcher, go launcher apk, go launcher , go launcher androi,

    ReplyDelete
  30. Mostly people have all the same things when they are writing academic task or any other writing, especially light music most people like during the writing.
    dream league soccer download , dream league soccer apk , download dream league soccer , dream league soccer

    ReplyDelete
  31. E-mail with many attractive features and convenience are the choice of most people around the world open. And I want to share to everyone a free webmail services
    outlook entrar , entrar no outlook , entrar outlook , outlook entrar

    ReplyDelete
  32. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know.
    wings.io l wingsio l wings io l wingsio game l play wingsio

    ReplyDelete


  33. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
    hotmail sign in | red ball 1

    ReplyDelete
  34. I think this is among the most important information for me. And I love those who read the article. However, I would like to clarify a few key issues, Website articles are really excellent, ideal, Excellent job, applause

    Edirne Kombi Servisi

    ReplyDelete
  35. Everyone loves the look and feel of a clean home. Thanks for choosing this topic for post and update me. Game Stick RPG 2 looks like your real life, you can get everything you want, game Douchebag workout 2 is to renew him, so that he can hook up with the sexy girl appearing in the introduction, return man 3 saves your progress, with Potty Racers do you want to fly to Mars with me?

    ReplyDelete
  36. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write.
    Thanks for sharing !
    tanki online 2 | 2048 game online

    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.