Doing the following is much better than using putpixel and a for loop, as numpy uses c-functions. The actual execution speed is about .3 seconds faster on a 240×320 RGBA image.
import numpy as np
arr = np.fromstring(buff,dtype=np.uint16).astype(np.uint32)
arr = 0xFF000000 + ((arr & 0xF800) >> 8 ) + ((arr & 0x07E0) << 5) + ((arr & 0x001F) << 19)
return Image.frombuffer('RGBA', (xdim,ydim), arr, 'raw', 'RGBA', 0, 1)
While it may seem like an odd bit shift, stuffing the channels into an int requires that it get stuffed as (most significant bit) ABGR (least significant bit). If you were to use the PIL call to putpixel, it would get stuffed as RGBA.