here's code that does pretty much the same thing for 16->32 conversion (taken from
directfb). adjust it to do what you want.
Code:
#define RGB16_TO_RGB32(pixel) ( (((pixel) & 0xF800) << 8) | \
(((pixel) & 0x07E0) << 5) | \
(((pixel) & 0x001F) << 3) )