def buildBitmap(rawData, w, h, maxColorVal):
"""ppm format, http://netpbm.sourceforge.net/doc/ppm.html
Constructs a wxBitmap. The <rawData> input is a raw
grayscale image, 8 bits per pixel."""
imageHdr = "P6\r%d %d\r%d\r" % (w, h, maxColorVal)
#expand grayscale to rgb
imageBuf = imageHdr + string.join([v*3 for v in rawData], "")
return wxBitmapFromImage( wxImageFromStream(
cStringIO.StringIO(imageBuf) ))
Virtually all the time is consumed expanding the 1 byte of grayscale
data into 3 bytes to get RGB. For example, V=128 is converted to
R=128,G=128,B=128.
On my computer I can display 3 frames per second of 360x240 data. If
I modify the imageBuf line to imageBuf = imageHdr + rawData*3, then I
can display 40fps. Of course, the image doesn't look right, but that
is the kind of speed that I desire.
I have tried a few things,
1) Building the string using cStringIO.
2) map instead of list comprehension.
3) I tried to get fancy with zip(rawData, rawData, rawData) followed
by string joins.
None of these had any speed improvement and 3) was much slower.
I am hoping not to have to write an extension module in "C".