Microcom 814M Programming Manual User Manual

Page 85

Advertising
background image

81

//************************************************//
int AntiRotateBmp90D(
char *pBmpData,
const int nPixelsOfWidth,
const int nPixelsOfHeight,
char *pBmpDataRotated
)
{

// Define process variables

int nBytesOfWidth = 0,nBytesOfHeight = 0;

int i=0,col=0,row=0,index = 0,colbyte = 0;

char*

midData;

unsigned char tempdata = 0,colnum = 0,rownum = 0;

unsigned char temp[8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};


//Comparing parameters

if (pBmpData == NULL || pBmpDataRotated == NULL) return 0;

if (nPixelsOfWidth <= 0 || nPixelsOfHeight <= 0) return 0;

if ((nPixelsOfWidth % 8) != 0 || (nPixelsOfHeight % 8) != 0) return 0;

//get real image dimension

nBytesOfWidth = (nPixelsOfWidth+31)/32*4;
nBytesOfHeight = nPixelsOfHeight / 8;

//White/black reverse,the value 1 in BMP data is for white which is contrary to the printer definition.

midData = (char*)malloc(nBytesOfWidth*nPixelsOfHeight+1);

for(i=0;i<nBytesOfWidth*nPixelsOfHeight;i++){midData[i] = 0xff-pBmpData[i];}

//Rotation. BMP data is arranged in lines while data downloaded to printer are arranged in columns.

for (row = 0; row <nPixelsOfWidth; row++){
for (colbyte = 0; colbyte < nBytesOfHeight; colbyte++){
index = row * nBytesOfHeight + colbyte;
pBmpDataRotated[index] = 0x00;
for (col = 0; col < 8; col++){

colnum = col % 8;

rownum = row % 8;
if(colnum

>=

rownum)

tempdata = temp[col] & (midData[(nPixelsOfHeight-1-colbyte*8-col) *
nBytesOfWidth + row / 8] >> (colnum-rownum));

else

tempdata = temp[col] & (midData[(nPixelsOfHeight-1-colbyte*8-col) *
nBytesOfWidth + row / 8] << (rownum-colnum));
pBmpDataRotated[index] |= tempdata;
}
}
}
//release

interim

buffer

Advertising