Monday, August 4, 2008

From SDL to MyOwnVideoImplementation (TM)

After trying out the SDL video demo, I realized that for a video editor I won't be needing to use sprites, 3D textures or anything like that. It would be esier to write my own Bitmap buffer in memory. So I did, and I ended up creating the wxVideoPanel and wxVideoOutputDevice classes.

Unfortunately, the screen refreshing routines were awful. No, worse. They were hideous. I had to calculate everything manually, handle the pixel color spaces, etc. There had to be a better way. And hence, I came up with syBitmap: A cross-platform implementation of an in-memory bitmap. It has a virtual MustAbort() function which you can adapt for multi-threading purposes.
Currently I've been able to replicate the SDL example, but I was too busy and tired so I couldn't upload the screenshot.

As an added bonus, I created the derived class syVODBitmap (VOD stands for Video Output Device), which also has Lock() and Unlock() functions (also for multi-threading).

The best part is that I could add a PasteFrom function in syBitmap, so that the copying also scales and centers the source bitmap so it will fit the destination. Unfortunately, the implementation isn't as fast as I wanted because it uses floating point math. But I plan to replace it with fixed point math so copying won't become an overhead.

Still, the implementation is both ugly and slow. So I ended up creating another class (which I have yet to commit to SVN): syBitmapCopier. The idea behind it is this: Instead of having to calculate a pointer by multiplying y*width and then adding x, and then obtaining the color format of the pixels, we just init the class with the source and destination bitmaps, and these members are calculated only once.

I have designed functions to copy pixels and increment only the source pointer, only the destination pointer, or both. I've also designed functions to copy entire rows and advance either / both of the pointers by one full row. This way we'll have no worries about having to recalculate parameters for each pixel or passing them through the stack. Who knows, maybe I can inline all of these functions to get a super-efficient bitmap copier.

As soon as I finish the syBitmapCopier implementation, I'll make a multi-threaded demo to see how many frames per second I can get. And then I'll start making the Video playback UI, which is already overdue.

No comments: