Tuesday, January 09, 2007

Blend modes and dash offsets

Draft of SVG 1.2 Full adds composition modes to SVG. Besides the typical Porter&Duff operators some additional blend modes are defined in it. Those modes are also very commonly seen in many Adobe Photoshop tutorials and people frequently asked for them in Qt. They include "screen", "multiply", "overlay", "plus", "difference", "hard and soft light" and a few less prominent ones.

We decided to implement them for 4.3. Unfortunately Gunnar said that he simply won't have time to implement them and since I consider them to be very important I sat down after work today and implemted those blend modes in Qt. So if you checkout tonight's snapshot of Qt you'll nice that QPainter has new CompositionMode's. If you looked at some of the Photoshop tutorials on the net on how to do lightning effects, now you'll be able to do them all in Qt which is rather nice.

Once I did that I decided that I'll go ahead and implement the other feature that was missing in Qt and is required by SVG which is: dash offsets for stroke. API wise to QPen and QPainterPathStroker I just added setDashOffset(qreal offset) methods which respectively set the dash offset for the rendering operations in Qt.

To play around with blend modes I took two input images - CD cover image from a band called H2O and a flare generated with Gimp, they looked as follows:

And I wrote a simple application that blends those in real time, and the results of two of the modes look as follows:

One can do a lot of really interesting things with the new blend modes.
Oh, and since I'm weird like that I just went ahead and added support for composition modes (and dash offsets of course) to QtSvg and from what I see QtSvg is currently the only open source SVG renderer supporting the extended blend modes which is a nice bonus :)


Anonymous said...

In the beta's for Inkscape, they have only just managed to get blurring working, then it is quite slow, then they have got all the other effects to put in. Then I thought blurring was good in that, but this brings new oppurtunities.

Now I have to wait for this brilliant capability to built into an application.

Zack just keeps giving and giving :)

Anonymous said...

are those FPS so high because the blended image is cached or is it blended on every frame and you just made a fantastic implementation?

as usual, thanks soooo much for this

sAra said...

Now I want this in Koffice :). Really I love your blog and all the stuff you get done are just amazing. YOu have to slow down so that the people developing Krita and Karbon can keep up with you.

lpotter said...

rock on dude!

Anonymous said...


Anonymous said...

Simply amazing!

Anonymous said...