BMP Writing Performance

Eddie Cottongim cottonsqueak at
Thu Apr 3 01:03:07 UTC 2003

Thanks for the feedback. Here is a first cut at a BMPWriter plugin (well
hopefully the last cut but it would be suprising if I got it right the first
time). So far it works well on everything I've tested. One nice thing is
that even the fallback code gives about a 6x speedup over the current

I also up refactoring the 'writing' methods of BMPReadWriter to be very
similar to the 'reading' ones to keep things organized.

For those keeping score on speed, on my test image (800x600x24bpp):

original BMPWriter:    10,100 ms
plugin fallback code:      1,200 ms
plugin:                                 50 ms

Writing color indexed bmps is still rather slow, but should be easy to
improve due to the refactoring. (The reading version is fast due to some
kind of voodoo and I didn't want to attempt that here.)

Let me know if there are problems. I may not be able to get back to this for
a few days so I thought I'd let anyone interested bang on it.


Andreas said:
True and we don't have it yet ;-( If you want to do this what you should be
doing is to write the "inverse" of the existing primitive - e.g., take
what's there (literally!) and simply change the inner loop which copies the
pixels to do the exact opposite: Instead of reading 3 bytes and write a
word, read a word and write three bytes. Note that the existing primitive
checks all of the invariants you'd have to test for already - so you can
really just go for the inner loop.

[Extra note: I consider this a *perfect* place to start if you want to learn
something about plugin programming. The task is simple, it's definitely
valuable, small enough that it can get integrated right away. You'll have to
"go through the motions" of plugin building you can study the existing code
see what it checks, why this is needed what the failure code in Smalltalk
should be doing etc]

  - Andreas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: BMPWriting-efc.1.cs.gz
Type: application/octet-stream
Size: 2485 bytes
Desc: not available
Url :

More information about the Squeak-dev mailing list