Playing around with Bitmaps

By: Steve Waring
Home Pages: Journal Dolphinharbor
Created: 20020923
Last Update: 20021014

Article overview

This weekends diversion was to play around with Bitmaps.

Bitmap FX

I found some code at codeproject, Really cool visual FX and decided to have a go at porting some of it to Smalltalk. The demo executable is worth a look. I really wanted the "Water" effect, but the "Fire" effect looked quicker to port.

The initial port was an ugly mess of C++ translated to Smalltalk. I had numerous off by one bugs to track down, but eventually got it working:

It was slow even at the smaller sizes. I spent some time profiling and converting all ByteArray and ExternalMemory accesses to primative methods. At the size in the screenshot above, the animation looks great, but on larger bitmaps it is still too slow.

I didnt attempt the "Water" effect. It seems to get down to doing bit-level manipulation, and I think I would be waiting a while to see a ripple. Not the right tool for the job but it would be interesting to see how it would run in VW. I had hoped to use the "Water" effect for a Splash screen for a project I am currently working on ...

Alpha Blending

Instead of doing the Alpha Blending in Smalltalk, I decided to try the Win32 functions. I couldnt see a way to do animations like the above, the Win32 functions blend two bitmaps, while the BmFireRoutine class modifies a data array to simulate the fire, and uses that to alpha-blend a palette color with the bitmap bytes.

I did come up with a new view/ImagePresenter resource that is effectively a combination of DoubleBufferedView and DolphinSplash with a <ValueConvertingControlView> protocol. Using this view resource, if you set an image into an ImagePresenter's valueModel, it will do an Alpha-Blend fade from the previous value image to the new image. Good fun, and could be useful for a project I am working on.

If anybody wants the code, please email me.

Thats about it for this weekends diversion ... well except for trying out Userland's Radio :)

Layered Windows

Make your CHB transparent

thumb

By Adding these methods:

UserLibrary>>setLayeredWindowAttributes: aWindowHandle crKey: aCOLORREF bAlpha: aBYTE dwFlags: aDWORD
"The SetLayeredWindowAttributes function sets the opacity and transparency color key of a layered window.
BOOL SetLayeredWindowAttributes(
HWND hwnd,
COLORREF crKey,
BYTE bAlpha,
DWORD dwFlags);"

<stdcall: bool SetLayeredWindowAttributes handle dword byte dword> ^self invalidCall
View>>setTransparentAlpha: anIntegerValue
"2 = LWA_ALPHA"

^UserLibrary default setLayeredWindowAttributes: self asParameter crKey: 0 bAlpha: anIntegerValue dwFlags: 2

And evaluating (or using flipper)

Note:Win2K only ... please only use an image you can afford to trash.



view := ClassBrowserShell allInstances first view.
view exStyleMask: 524288"WS_EX_LAYERED" set: true recreateIfChanged: false.
view setTransparentAlpha: 150

Non Rectangular Windows

... Coming soon!

Copyright Steve Waring 2002.