|
如果你要转载我的帖子,请著名( "作者:叶风(windlucid) qq:239302992")
剑侠系列图片相关贴子。
第一篇:关于金山公司的剑侠情缘系列游戏的图片格式 之一
第二篇:关于金山公司的剑侠情缘系列游戏的图片格式 之二
第三篇:关于金山公司的剑侠情缘系列游戏的图片格式 之三
新贴:[em3] [em3] [em3]
第一篇:“目标”软件 之游戏图片格式 xbm 和 资源库文件
第二篇:“目标”软件 之游戏图片格式 xbm 和 资源库文件 之二
全代码:
声明: 本文的程序经过调试,成功运行。
我不会对本程序所带来的一切后果负责。
感谢 金山公司的美工(图片太美了)
本文没有任何商业行为,纯属自娱自乐
有人问我,为什么老是研究图片格式。
我说:
1。我没有美工,我只有自己,我不会画画。但是,我要精美的图片。
2。我没有人询问,想知道成功游戏中的图片粘贴方法,地图的建立方法。。。所有游戏中不公开的方法,只有研究游戏运行时的内存。
3。我自己写的引擎,太长,我也没办法抄到这里。只有发一点哗众取宠的贴子,来吸引你们的眼球。
4。我还没想到,想到了,一定说。(好苦啊)
代码:
//我可是从家里电脑抄到纸上,再从纸上抄到这里,大家要珍惜啊。
// 别忘了给我打分!!(windlucid 用乞求的目光 注视着每一位 拷贝代码的人)
//
//具体的对结构的解释请看 "关于金山公司的剑侠情缘系列游戏的图片格式 之二"
//调色板的结构:
struct MPCPALETE
{
unsigned blue:8;
unsigned green:8;
unsigned red:8;
unsigned alpha:8; //不知道什么作用
}
//图片数据的头结构:
struct MPCPICDATAHEADER
{
int picDataSize;
int picWidth;
int picHeight;
int NULL1; // 0 //不知道是什么
int NULL2; // 0
}
//MPC 图片文件的头结构:
struct MPCFILEHEADER
{
char mpcFlag[16]; // 标志 "MPC File Ver2.0"
int mpcNULL1[12]; // 0
int mpcPicDataSize; // 图片数据长度
int mpcMaxWidth; // 所有图片中最大的宽度
int mpcMaxHeight;
int mpcPicCount;
int mpcPicBitCount; // 8
int mpcPalleteSize; // 调色板数据的长度
int mpcNull3; // 0
}
void savebmp(const char *bmpfileName,unsigned char *
bmpData,int nDataLen,int nWidth,int nHeight);
void mpc2bmp(const char *mpcFileName)
{
FILE *mpcfile=NULL;
int nbmpFileNameLen=strlen(mpcFileName);
char *bmpfileName=new char[nbmpFileNameLen+3];
char *bmpFileName=new char[nbmpFileNameLen+3];
memset(bmpFileName,0,nbmpFileNameLen+3);
memset(bmpfileName,0,nbmpFileNameLen+3);
strcpy(bmpFileName,mpcFileName);
strcat(bmpFileName,"%d.bmp");
nbmpFileNameLen-=4;
MPCFILEHEADER mpcFileHeader;
MPCPICDATAHEADER mpcPicDataHeader;
unsigned char *picData=NULL;
unsigned char *bmpData=NULL;
int row=0;
int col=0;
int maxrow=0;
int maxcol=0;
int nextColorOffset=0;
int nextColorOffsetInBmp=0;
int npicCount=0;
int bmpBufLen=0;
int mpcBufLen=0;
int i=0;
mpcfile=fopen(mpcFileName,"rb");
if(mpcfile==NULL)
return;
fread(&mpcFileHeader,1,sizeof(mpbFileHeader),mpcfile);
MPCPALETE *mpcPalete=new MPCPALETE mpcFileHeader.mpcPalleteSize];
fread(mpcPalete,4,mpcFileHeader.mpcPalleteSize,mpcfile);
int *mpcPicOffset=new int[mpcFileHeader.mpcPicCount];
fread(mpcPicOffset=n,1,mpcFileHeader.mpcPicCount*4,mpcfile);
fread(&mpcPicDataHeader,1,sizeof(mpcPicDataHeader),mpcfile);
mpcBufLen=mpcPicDataHeader.picSize-sizeof(mpcPicDataHeader);
picData=new unsigned char[mpcBufLen];
fread(picData,1,mpcBufLen,mpcfile);
bmpBufLen=mpcPicDataHeader.picHeight*(mpcPicDataHeader.picWidth*3+mpcPicDataHeader.picWidth%4);
bmpData=new unsigned char[bmpBufLen];
maxcol=mpcPicDataHeader.picWidth;
maxrow=mpcPicDataHeader.picHeight;
while(1)
{
col =0;
row =0;
nextColorOffset=0;
nextColorOffsetInBmp=0;
while(nextColorOffset<mpcBufLen)
{
if(picData[nextColorOffset]>0x80)
{
i=picData[nextColorOffset]&0x7F;
while(i>0)
{
bmpData[nextColorOffsetInBmp++]=0xFF;
bmpData[nextColorOffsetInBmp++]=0x00;
bmpData[nextColorOffsetInBmp++]=0xFF;
--i;
}
col=0;
++row;
}
++nextColorOffset;
}
i=picData[nextColorOffset];
++nextColorOffset;
while(i>0)
{
bmpData[nextColorOffsetInBmp]=
mpcPalete[picData[nextColorOffset]].blue;
++nextColorOffsetInBmp;
bmpData[nextColorOffsetInBmp]=
mpcPalete[picData[nextColorOffset]].green;
++nextColorOffsetInBmp;
bmpData[nextColorOffsetInBmp]=
mpcPalete[picData[nextColorOffset]].red;
++nextColorOffsetInBmp;
++nextColorOffset;
++col;
++i;
}
if(col==maxcol)
{
for(i=0;i<mpcPicDataHeader.picWidth%4;i++)
{
bmpData[nextColorOffsetInBmp]=0;
++nextColorOffsetInBmp;
}
col=0;
++row;
}
}
wsprintf(bmpfileName,bmpFileName,npicCount);
savebmp(bmpfileName,bmpData,bmpBufLen,
mpcPicDataHeader.picWidth,
mpcPicDataHeader.picHeight);
delete bmpData;
delete picData;
++npicCount;
if(npicCount<mpcFileHeader.mpcPicCount)
{
fread(&mpcPicDataHeader,1,sizeof(mpcPicDataHeader),mpcfile);
mpcBufLen=mpcPicDataHeader.picSize-
sizeof(mpcPicDataHeader);
picData=new unsigned char[mpcBufLen];
bmpBufLen=mpcPicDataHeader.picHeight*
mpcPicDataHeader.picWidth*3+
mpcPicDataHeader.picWidth%4);
bmpData=new unsigned char[bmpBufLen];
fread(picData,1,mpcbufLen,mpcFile);
}
else
break;
}
void savebmp(const char *bmpfileName,unsigned char *
bmpData,int nDataLen,int nWidth,int nHeight)
{
FILE *bmpFile=NULL;
BITMAPFILEHEADER bmpHeader;
BITMAPINFO bmpInfo;
unsigned char *tempData;
int nPitch=nWidth*3+nWidth%4;
tempData=bmpData+nDataLen-nPitch;
bmpFile=fopen(bmpfileName,"w+b");
if(bmpFile==NULL)
return ;
bmpHeader.bfOffBits=54;
bmpHeader.bfSize=nDataLen+54;
bmpHeader.bfType=19778; //"BM"
bmpHeader.bfReserved1=0;
bmpHeader.bfReserved2=0;
bmpInfo.bmiHeader.biSize=40;
bmpInfo.bmiHeader.biWidth=nWidth;
bmpInfo.bmiHeader.biHeight=nHeight;
bmpInfo.bmiHeader.biPlanes=1;
bmpInfo.bmiHeader.biBitCount=24;
bmpInfo.bmiHeader.biCompression=0;
bmpInfo.bmiHeader.biSizeImage=nDataLen;
bmpInfo.bmiHeader.biXPelsPerMeter=3780;
bmpInfo.bmiHeader.biYPelsPerMeter=3780;
bmpInfo.bmiHeader.biClrUsed=0;
bmpInfo.bmiHeader.biClrImportant=0;
fwrite(&bmpHeader,1,sizeof(bmpHeader),bmpFile);
fwrite(&bmpInfo,1,sizeof(bmpInfo),bmpFile);
fseek(bmpFile,(-1)*sizeof(bmpInfo.bmiColors),SEEK_CUR);
for(;nHeight>0;--nHeight)
{
fwrite(tempData,1,nPicth,bmpFile);
tempData-=nPitch;
}
fclose(bmpFile);
}
朋友们,先不要用这些代码,我要回去吃饭了,
终于写完了。 |
|