#include<fstream.h>#include<iostream.h>#include<windows.h>void main(){ ifstream src(argc[1],ios::in|ios::binary);//lzs ofstream dst(argc[2],ios::out|ios::binary);//bmp if(!src||!dst) { cout<<"file open error."; return; } // Load the texture int iWidth=0, iHeight=0, iColors=0; src.read((unsigned char *)&iColors,4); if(iColors)src.seekg(0x10,ios::beg); src.read((unsigned char *)&iWidth,2); src.read((unsigned char *)&iHeight,2); //strcture for bitmap BITMAPINFO* bmi = (BITMAPINFO*)malloc(sizeof(BITMAPINFOHEADER)); bmi->bmiHeader.biBitCount = 16; bmi->bmiHeader.biClrImportant = 0; bmi->bmiHeader.biClrUsed = 0; bmi->bmiHeader.biCompression = BI_RGB; bmi->bmiHeader.biHeight = -iHeight;//must be negative bmi->bmiHeader.biPlanes = 1; bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader); bmi->bmiHeader.biSizeImage = 0; //iWidth*iHeight*2 bmi->bmiHeader.biWidth = iWidth; bmi->bmiHeader.biXPelsPerMeter = 0; bmi->bmiHeader.biYPelsPerMeter = 0;/* src.seekg(0xF0,ios::beg);//palette src.read((unsigned char *)bmi->bmiColors,4*iColors); for (int i=0;i<iColors;i++) bmi->bmiColors[i].rgbReserved = 0;// Make sure rgbReserved is zero*/ unsigned char *bits = (unsigned char*)malloc(iWidth*iHeight*2);//data src.read(bits,iWidth*iHeight*2); unsigned int tmpFlip,tmp; for (int i=0;i<iWidth*iHeight*2;i+=2) { tmp=bits[i]+(bits[i+1]<<8); tmpFlip = (tmp & 0x7C00) >> 10; // Red -> Blue tmpFlip |= (tmp & 0x07E0); // Green -> Green tmpFlip |= (tmp & 0x001F) << 10; // Blue -> Red tmp = tmpFlip; bits[i]=tmp;bits[i+1]=tmp>>8; } // Build the bitmap file BITMAPFILEHEADER bmfh; //BITMAPINFOHEADER bmih; bmfh.bfType = 'MB'; // BM (byteflipped) bmfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + iWidth*iHeight*2; bmfh.bfReserved1 = 0; bmfh.bfReserved2 = 0; bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); dst.write((unsigned char *)&bmfh, sizeof(bmfh)); dst.write((unsigned char *)&bmi->bmiHeader, sizeof(BITMAPINFOHEADER));// dst.write((unsigned char *)bmi->bmiColors, iColors*sizeof(RGBQUAD));// for (int j=0;j<iHeight;j++)// dst.write(bits+(iHeight-j-1)*iWidth*2,iWidth*2); //if iHeight>0 dst.write(bits,iWidth*iHeight*2); free(bmi); free(bits); src.close(); dst.close(); return;}