当前位置: 技术问答>linux和unix
同一段程序在solaris9 x86和solaris9 sparc运行问题
来源: 互联网 发布时间:2016-03-27
本文导语: 下边是一个加载bmp图片的函数 BYTE *LoadBMP(char * filenameBitmap,//文件名 UINT *width, UINT *height) { BITMAP inBM; BYTE m1,m2; long filesize; short res1,res2; long pixoff; long bmisize; ...
下边是一个加载bmp图片的函数
BYTE *LoadBMP(char * filenameBitmap,//文件名
UINT *width,
UINT *height)
{
BITMAP inBM;
BYTE m1,m2;
long filesize;
short res1,res2;
long pixoff;
long bmisize;
long compression;
unsigned long sizeimage;
long xscale, yscale;
long colors;
long impcol;
BYTE *outBuf=NULL;
// for safety
*width=0; *height=0;
// init
//m_errorText="OK";
DWORD m_bytesRead=0;
FILE *fp;
fp=fopen(filenameBitmap,"rb");
if (fp==NULL) {
//CString msg;
//msg="Can't open file for reading :n"+fileName;
//m_errorText=msg;
printf("Can't open file for reading :%sn",filenameBitmap);
return NULL;
} else {
long rc;
rc=fread((BYTE *)&(m1),1,1,fp); m_bytesRead+=1;
if (rc==-1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((BYTE *)&(m2),1,1,fp); m_bytesRead+=1;
if (rc==-1)printf("Read Error!n");;
if ((m1!='B') || (m2!='M')) {
printf("Not a valid BMP File!n");
fclose(fp);
return NULL;
}
////////////////////////////////////////////////////////////////////////////
//
// read a ton of header stuff
rc=fread((long *)&(filesize),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((int *)&(res1),2,1,fp); m_bytesRead+=2;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((int *)&(res2),2,1,fp); m_bytesRead+=2;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(pixoff),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(bmisize),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(inBM.bmWidth),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(inBM.bmHeight),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((int *)&(inBM.bmPlanes),2,1,fp); m_bytesRead+=2;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((int *)&(inBM.bmBitsPixel),2,1,fp); m_bytesRead+=2;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(compression),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(sizeimage),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(xscale),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(yscale),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(colors),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(impcol),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
////////////////////////////////////////////////////////////////////////////
// i don't do RLE files
if (compression!=BI_RGB) {
printf("This is a compressed file.n");
fclose(fp);
return NULL;
}
if (colors == 0) {
colors = 1
BYTE *LoadBMP(char * filenameBitmap,//文件名
UINT *width,
UINT *height)
{
BITMAP inBM;
BYTE m1,m2;
long filesize;
short res1,res2;
long pixoff;
long bmisize;
long compression;
unsigned long sizeimage;
long xscale, yscale;
long colors;
long impcol;
BYTE *outBuf=NULL;
// for safety
*width=0; *height=0;
// init
//m_errorText="OK";
DWORD m_bytesRead=0;
FILE *fp;
fp=fopen(filenameBitmap,"rb");
if (fp==NULL) {
//CString msg;
//msg="Can't open file for reading :n"+fileName;
//m_errorText=msg;
printf("Can't open file for reading :%sn",filenameBitmap);
return NULL;
} else {
long rc;
rc=fread((BYTE *)&(m1),1,1,fp); m_bytesRead+=1;
if (rc==-1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((BYTE *)&(m2),1,1,fp); m_bytesRead+=1;
if (rc==-1)printf("Read Error!n");;
if ((m1!='B') || (m2!='M')) {
printf("Not a valid BMP File!n");
fclose(fp);
return NULL;
}
////////////////////////////////////////////////////////////////////////////
//
// read a ton of header stuff
rc=fread((long *)&(filesize),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((int *)&(res1),2,1,fp); m_bytesRead+=2;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((int *)&(res2),2,1,fp); m_bytesRead+=2;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(pixoff),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(bmisize),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(inBM.bmWidth),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(inBM.bmHeight),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((int *)&(inBM.bmPlanes),2,1,fp); m_bytesRead+=2;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((int *)&(inBM.bmBitsPixel),2,1,fp); m_bytesRead+=2;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(compression),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(sizeimage),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(xscale),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(yscale),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(colors),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
rc=fread((long *)&(impcol),4,1,fp); m_bytesRead+=4;
if (rc!=1) {printf("Read Error!n"); fclose(fp); return NULL;}
////////////////////////////////////////////////////////////////////////////
// i don't do RLE files
if (compression!=BI_RGB) {
printf("This is a compressed file.n");
fclose(fp);
return NULL;
}
if (colors == 0) {
colors = 1