/**
Code adapted from CxImage (http://www.xdp.it/cximage.htm)
*/
static BYTE*
Rotate90(BYTE *src, int src_width, int src_height, int bpp ) {
int x, y, y2;

int dst_width = src_height;
int dst_height = src_width;

// get src and dst scan width
int src_pitch = (src_width*bpp + 7) /8 + 3 & ~3;
int dst_pitch = (dst_width*bpp + 7) /8 + 3 & ~3;




// allocate dst image
BYTE *dst = new BYTE[dst_pitch * dst_height];
if(NULL == dst) return NULL;

if(bpp == 1) {
// speedy rotate for BW images

BYTE *sbits, *dbits, *dbitsmax, bitpos, *nrow, *srcdisp;
div_t div_r;

BYTE *bsrc = src;
BYTE *bdest = dst;
dbitsmax = bdest + dst_height * dst_pitch - 1;

for(y = 0; y < src_height; y++) {
// figure out the column we are going to be copying to
div_r = div(y, 8);
// set bit pos of src column byte
bitpos = (BYTE)(128 >> div_r.rem);
srcdisp = bsrc + y * src_pitch;
for (x = 0; x < src_pitch; x++) {
// get source bits
sbits = srcdisp + x;
// get destination column
nrow = bdest + (dst_height - 1 - (x * 8)) * dst_pitch + div_r.quot;
for (int z = 0; z < 8; z++) {
// get destination byte
dbits = nrow - z * dst_pitch;
if ((dbits < bdest) || (dbits > dbitsmax)) break;
if (*sbits & (128 >> z)) *dbits |= bitpos;
}
}
}
}
else if((bpp == 8) || (bpp == 24) || (bpp == 32)) {

}

return dst;
}