Saturday 7 July 2007

ShivaVG: open-source ANSI C OpenVG

Vector graphic algorithms on CPU are more or less reaching their limits and the only hope to get software like Adobe Illustrator speeded up is probably by installing a faster processor into your PC. I've started an open-source project for a vector-graphics drawing library that would use hardware acceleration already a year ago under the name libShiva. However, it never took up really well and recently I realized why.

Basically, it's the same problem as with other current open-source vector-graphics APIs that utilize graphic card. They are usually a part of a very large toolkit or framework and it's hard to use the sole drawing API without having to link your project against and make it dependent on the whole framework. This goes for projects like Qt (and it's OpenGL drawing widget) as well as Amanith, which itself depends on Qt for creaton of a window and initialization of an OpenGL context.

It was the same problem with libShiva - I tried to implement a HW accelerated renderer and a whole GUI toolkit together with event management like Flash offers in its ActionScript in one single library. That made the lib very heavy for use, but on the other hand, what we really need is a lightweight API that just renders the graphics, possibly written in ANSI C to be as portable as possible.

And here's where OpenVG came into play. It is a royalty free API developed by Khronos Group (http://www.khronos.org/openvg). Originally it targets smaller, portable devices (e.g. mobile phones, PDA's) but the specification itself encourages PC implementations as well. What is pretty obvious is that on hand-held devices the API will be implemented in hardware and there are already plans by nVidia and other companies to design chips to handle OpenVG.

Since such hardware is not available for PCs yet, I decided to implement the API on top of OpenGL which is basically the same approach that Qt's OpenGL painter and Amanith use. Actually, there is already a project named AmanithVG which is another implementation of the OpenVG API, but it's commercial and closed source. Usually, when I see good projects made closed-source and commercialized, I get really pissed off, and I feel the urge to start a similar open-source project. Besides, after having a look at the API it felt like this is exactly what FOSS community would need. Moreover, as a response to a blog entry by Zack Rusin regarding the implementation of the OpenVG API on top of Qt (link), there was already a request for an ANSI C version of it.

So, I took the rendering code from libShiva project, translated it from C++ to ANSI C and wrapped into OpenVG API, to create a new implementation called ShivaVG. So far, most of the code for creating, transforming, interpolating and drawing paths is done. The imaging support is currently very poor (just RGBA_8888 format supported), but both linear and radial gradients work and full porter-duff blending is being developed. The source code is accessible via subversion at SourceForge:

$ svn co https://shivavg.svn.sourceforge.net/svnroot/shivavg/trunk

After optimizing the code a little bit the performance is even much better than the old libShiva implementation. Check the lower-left corner of the example program screenshots to see the number of frames per second - that's on Core 2 Duo 2.16 with GeForce 7600 GT. The EGL API for creating an OpenVG context is not implemented yet, but you can use any kind of technique to achieve that (GLUT, SDL, native). The only thing to do then is to call vgCreateContextSH prior to any other VG call and vgDestroyContextSH when you are done. The example programs use GLUT, so you will need that to compile them. There are even Visual Studio projects provided for those of you who use Windows.




iBook died: retrieving the data

Can you imagine what's the worst things that can happen when you are at the end of semester, polishing your last assignments in order to achieve the highest marks... Can you imagine loosing all that data just a few days before the due date? Well, that's just what happened to me!

I usually work at home on my PC, but occasionally I used to copy the data to my iBook to work at the uni in case I had some free time in between the lectures. Yeah, I used to, because my iBook is now dead, without a single spark of life in it. Well, what happened is: my break was just going to finish and I routinely stretched my arm towards my bag pocket to search for the USB key. I always do that, you know, just in case anything goes bad, I copy the last files I worked on before putting the laptop to sleep.

Well, to my surprise I somehow forgot the usb key at home, but I thought 'That's ok, its not like something is going to happen exactly today, right'. So I close the iBook and wait for that cute white 'sleep led' to light up.... but nothing happens. I lift the screen back up - black... I drag over the touchpad, press space a few times.... nothing.

Actually, it was not the first time such a thing happened - it looks like the laptop is somehow bugged and stops somewhere in between the 'sleep' and 'awake' state. As I always do, I detached the battery to turn iBook off and restart it again. There's no restart button on that laptop anyway. But this time it wouldn't turn on. The only thing I heard was the short 'scratching' of the disk as it turned on and that was it. I tried to turn it on a few more times later at home but to no avail.

I took the laptop to the nearest Apple store and they told me they want 70$ AUD just to 'have a look at it' and 150$ more to retrieve the data. I thought no way, I am not paying that money for something I can do myself. Fortunately, I have some really cool friends that use a Mac as well, and one of them provided me with an e-book with the pictures of the whole process of disassembling an iBook which came very much handy! If you want to do it too, I suggest you google for 'ibook repair book' ;)

So I went to nearest Dick Smith to buy all the necessary tools like tiny hex screwdrivers etc. The disassembling itself went quite smooth, the largest struggle being sorting out all the screws so I could properly place them back when assembling the laptop again. What I did was, I just placed them on a sheet of paper, writing aside where the screws go, but I suggest buying a toolbox with those small compartments for screws, because it's very easy to accidentally move the paper and mix all the screws lying on it.

After 'tearing' apart the laptop's case and protective shields, removing the memory card and airport card and all the other necessary things, the flashy iBook's internals showed up. You can see how smartly and precisely its architecture was designed to keep it as slim as possible. Everything just fits nicely together. However, this super slim architecture makes it hard to replace one single thing, so you have to really open both sides of the laptop (upper and lower) to be able to get the hard drive out. Well, a few more screwdriver turns and the hard drive was finally lying in front of me. My eyes were almost slightly aroused as I held it in my hand, knowing my precious data is somewhere there, among those ones and zeros! :)

I forgot one thing, though: the hard drive inside a laptop of course doesn't use the 3.5 inch IDE connector that PC's do. So I had to buy this 3.5 to 2.5 inch IDE adapter. Unfortunately, I also had no place to fix the tiny hard drive with screws inside the PC case, so I just used a CD case cover. Remember that you shouldn't block the openings through which the disk is cooling or it might overheat. The final copying of the data was trivial. Use linux, mount the mac's HFS+ filesystem and there you go!