Created
August 10, 2016 14:53
-
-
Save scalone/a5e9d16120822b24db8d6d9967a38cd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <signal.h> | |
#include <fcntl.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <osal.h> | |
#include <xui.h> | |
#include "properties.h" | |
struct tagBITMAPFILEHEADER | |
{ | |
unsigned short bfType; | |
unsigned int bfSize; | |
unsigned short bfReserved1; | |
unsigned short bfReserved2; | |
unsigned int bfOffBits; | |
} | |
#ifdef _MSC_VER | |
#pragma warning(disable:4103) | |
#pragma pack(1) | |
#else | |
__attribute__ ((__packed__)) | |
#endif | |
; | |
typedef struct tagBITMAPFILEHEADER BITMAPFILEHEADER; | |
struct tagBITMAPINFOHEADER | |
{ | |
unsigned int biSize; | |
unsigned int biWidth; | |
unsigned int biHeight; | |
unsigned short biPlanes; | |
unsigned short biBitCount; | |
unsigned int biCompression; | |
unsigned int biSizeImage; | |
unsigned int biXPelsPerMeter; | |
unsigned int biYPelsPerMeter; | |
unsigned int biClrUsed; | |
unsigned int biClrImportant; | |
} | |
#ifdef _MSC_VER | |
#pragma warning(disable:4103) | |
#pragma pack(1) | |
#else | |
__attribute__ ((__packed__)) | |
#endif | |
; | |
typedef struct tagBITMAPINFOHEADER BITMAPINFOHEADER; | |
int BmpConvert(char *file, unsigned char *logo) | |
{ | |
int i, j, k, m, bFlag, ibit; | |
int fh; | |
int iLcdLines, nMaxByte; | |
BITMAPFILEHEADER tBmFileHeader; | |
BITMAPINFOHEADER tBmInfoHeader; | |
unsigned char bLogo, bTemp, bData, temp[8]; | |
unsigned long DataSizePerLine; | |
char sBuf[100]; | |
unsigned char b, ss, pMem[524000]; | |
unsigned char *tlogo; | |
fh = open(file, O_RDONLY); | |
if (fh == -1) | |
{ | |
printf("open bmp file err!\n"); | |
return -1; | |
} | |
if (read(fh, &tBmFileHeader, sizeof(BITMAPFILEHEADER)) == -1) | |
{ | |
printf("Problem reading file\n"); | |
close(fh); | |
return -1; | |
} | |
if (read(fh, &tBmInfoHeader, sizeof(BITMAPINFOHEADER)) == -1) | |
{ | |
printf("Problem reading file\n"); | |
close(fh); | |
return -1; | |
} | |
if (tBmInfoHeader.biBitCount != 1) | |
{ | |
printf("biBitCount=%x, Must be monochrome bitmap file!!!\n", tBmInfoHeader.biBitCount); | |
close(fh); | |
return -1; | |
} | |
if (tBmInfoHeader.biWidth > 576) | |
{ | |
printf("The width of bitmap must <= 192!!!\n"); | |
close(fh); | |
return -1; | |
} | |
if (read(fh, &temp, 8) == -1) | |
{ | |
printf("Problem reading file\n"); | |
close(fh); | |
return -1; | |
} | |
if ((temp[0] == 0xFF) && (temp[1] == 0xFF) && (temp[2] == 0xFF)) | |
{ | |
bFlag = 1; | |
} | |
else if((temp[0] == 0x00) && (temp[1] == 0x00) && (temp[2] == 0x00)) | |
{ | |
bFlag = 0; | |
} | |
ibit = tBmInfoHeader.biWidth%8; | |
if ( 0 == ibit ) | |
{ | |
b = 0x00; | |
} | |
else | |
{ | |
b = 2^(tBmInfoHeader.biWidth/8); | |
} | |
DataSizePerLine= (tBmInfoHeader.biWidth*tBmInfoHeader.biBitCount+31)/8; | |
DataSizePerLine= DataSizePerLine/4*4; | |
tlogo=logo; | |
iLcdLines = tBmInfoHeader.biHeight; | |
*tlogo = (unsigned char)iLcdLines; | |
tlogo++; | |
memset(pMem, 0xff, iLcdLines*tBmInfoHeader.biWidth); | |
for(i=tBmInfoHeader.biHeight-1,j=0; i>=0; i--,j++) | |
{ | |
if (lseek(fh, tBmFileHeader.bfOffBits+i*DataSizePerLine, SEEK_SET) == -1) | |
{ | |
printf("lseek to current position failed\n"); | |
close(fh); | |
return -1; | |
} | |
if (read(fh, sBuf, DataSizePerLine) == -1) | |
{ | |
printf("Problem reading file\n"); | |
close(fh); | |
return -1; | |
} | |
if(bFlag) | |
{ | |
for (k = 0; k < DataSizePerLine; k++) | |
{ | |
if (k < tBmInfoHeader.biWidth/8) | |
{ | |
pMem[j*DataSizePerLine+k] = ~(sBuf[k]); | |
} | |
else if(k == tBmInfoHeader.biWidth/8) | |
{ | |
pMem[j*DataSizePerLine+k] = ~(sBuf[k] | 0xFF - b); | |
} | |
else | |
{ | |
pMem[j*DataSizePerLine+k] = 0x00; | |
} | |
} | |
} | |
else | |
{ | |
memcpy(pMem+j*DataSizePerLine, sBuf, DataSizePerLine); | |
} | |
} | |
close(fh); | |
for(i=0; i<iLcdLines; i++) | |
{ | |
nMaxByte =72; | |
*tlogo = (unsigned char)(nMaxByte/256); | |
tlogo++; | |
*tlogo = (unsigned char)(nMaxByte%256); | |
tlogo++; | |
for(j=0; j<(int)DataSizePerLine; j++) | |
{ | |
if (j >= 72) | |
break; | |
bLogo = 0x00; | |
bData= *(pMem+i*DataSizePerLine+j); | |
for(m=7; m>=0; m--) | |
{ | |
bTemp = (bData>>m)&0x01; | |
if (bTemp == 0x00) | |
bLogo |= 0x01<<m; | |
} | |
if (j ==tBmInfoHeader.biWidth/8) | |
{ | |
ss =0x00; | |
for(m=0; m<tBmInfoHeader.biWidth%8; m++) | |
{ | |
ss |=1<<(7-m); | |
} | |
bLogo &=ss; | |
} | |
*tlogo = bLogo; | |
tlogo++; | |
if (j ==tBmInfoHeader.biWidth/8) | |
{ | |
j++; | |
break; | |
} | |
} | |
if (DataSizePerLine < 72) | |
{ | |
memset(sBuf, 0, sizeof(sBuf)); | |
for(m=0; j<72; m++,j++) | |
{ | |
*tlogo = (unsigned char)sBuf[m]; | |
tlogo++; | |
} | |
} | |
} | |
return 0; | |
} | |
int main(int argc, char **argv) | |
{ | |
............ | |
pSignWin = XuiCreateSignatureBoard(); | |
XuiShowWindow(pSignWin, 1, 0); | |
............. //signature | |
XuiImg *imgTmp; | |
unsigned char *logo; | |
logo = (unsigned char*)malloc(sizeof(unsigned char)*20000); | |
imgTmp = XuiSigBoardImg(pSignWin); | |
XuiImgSaveToFile(imgTmp, "/tmp/sign.mbmp"); | |
XuiImgFree(imgTmp); | |
BmpConvert("/tmp/sign.mbmp", logo); | |
OsPrnOpen(PRN_REAL, NULL); | |
OsPrnPutImage(logo); | |
OsPrnStart(); | |
OsPrnClose(); | |
free(logo); | |
XuiDestroyWindow(pSignWin); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment