Let there be color

Posted by Ariya Hidayat on July 5, 2008 · 5 comments

Time for another fresh example for the Graphics Dojo. This time I present a small tool that does nothing but showing the famous HSV cylinder. To give some realism, subtle blurred reflection is also added but can be easily disabled. Manual full-scene anti-aliasing is provided by the usual multisampling approach. Everything is done using pure QImage per-pixel manipulation along with some tricks, no OpenGL (or even its GLSL) is involved.

HSV Pie

For the code, check it out using:

svn checkout svn://labs.trolltech.com/svn/graphics/dojo/hsvpie

Note that the tool is not optimized for speed (evidenced by lots of setPixel() calls) so there is definitely room for improvement. Some possible further enhancements left as exercises for the readers are interactivity (mouse dragging to change e.g. the depth of the pie) and threaded rendering (so that the application remains responsive, just adapt the Mandelbrot example).

Have some dojo-fun!

QShare(this)

Possibly related posts:

  1. Improving the rendering performance with more SIMD
  2. Some WebKit Hybrid Stuff

5 comments

1 Sebastian Werner July 7, 2008 at 10:16 pm
 

You may be interested in this one. Fabian Jakobs has ported the whole thing to JavaScript using the Canvas element.

http://news.qooxdoo.org/let-there-be-color-in-the-browser

2 ariya July 7, 2008 at 11:26 pm
 

@Sebastian Werner: the HTML Canvas version looks really cool!

3 Fabian Jakobs July 7, 2008 at 11:57 pm
 

Thanks :-)

Take a look at the JavaScript code. You will be surprised how similar it is to your C++ version.

4 anonymous coward July 9, 2008 at 12:10 am
 

Hm, I wonder why in line 211 of hsvpie.cpp we have:
class QImage createHsvPie(int radius, int depth, qreal ratio, qreal limit, qreal init)
{

}

instead of

QImage createHsvPie(int radius, int depth, qreal ratio, qreal limit, qreal init)
{

}

what is the keyword class is doing there and why does it compile without any errors?

5 Daniel Albuschat July 23, 2008 at 1:23 pm
 

The “class”-keyword in this context is used for in-place forward-declarations, but doesn’t quite make sense because we’re not using pointers here.
You can return previously unknown classes in two ways. The first is the usual forward-declaration:

class Return;

Return *returnSomething();

The other way is the in-place forward-declaration:

class Return *returnSomething();

By prefixing the “class”, Return does not need to be declared in this scope. It only needs to be declared when dereferencing the resulting pointer later.
When not using pointers or references, you can still use the “class”-prefix on return types and parameter types, but the class needs to be fully declared at this point.

Comments on this entry are closed.

Previous post:

Next post: