#include "BassPath.h"
bool operator<(const _point &op1, const _point &op2)
{
if (op1.x<op2.x)
return true;
if (op1.x>op2.x)
return false;
return op1.y<op2.y;
}
bool operator==(const _point &op1, const _point &op2)
{
return (op1.x==op2.x)&&(op1.y==op2.y);
}
int WriteBitmapFile(char* filename,_mapData &m_pmap)
{
int width = m_pmap.m_l;
int height = m_pmap.m_h;
FILE *filePtr;
BITMAPFILEHEADER bitmapFileHeader;
BITMAPINFOHEADER bitmapInfoHeader;
int imageIdx;
unsigned char tempRGB;
filePtr = fopen(filename,"wb");
if (!filePtr)
return 0;
bitmapFileHeader.bfSize = sizeof(BITMAPFILEHEADER);
bitmapFileHeader.bfType = 0x4D42;
bitmapFileHeader.bfReserved1 = 0;
bitmapFileHeader.bfReserved2 = 0;
bitmapFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfoHeader.biPlanes = 1;
bitmapInfoHeader.biBitCount = 24;
bitmapInfoHeader.biCompression = BI_RGB;
bitmapInfoHeader.biSizeImage = width*abs(height)*3;
bitmapInfoHeader.biXPelsPerMeter=0;
bitmapInfoHeader.biYPelsPerMeter=0;
bitmapInfoHeader.biClrImportant=0;
bitmapInfoHeader.biClrUsed=0;
bitmapInfoHeader.biWidth=width;
bitmapInfoHeader.biHeight=height;
BYTE *imageData = new BYTE[bitmapInfoHeader.biSizeImage];
BYTE *Buffer;
for (int i=0; i<height; i++)
{
Buffer = imageData+bitmapInfoHeader.biSizeImage-(i+1)*width*3;
for(int j=0; j<width; j++)
{
if (m_pmap.mdata[i][j] == -2)
{
*(Buffer+j*3) = 0;
*(Buffer+j*3+1)=0;
*(Buffer+j*3+2)=0;
}
else if(m_pmap.mdata[i][j] == -1)
{
*(Buffer+j*3) = 255;
*(Buffer+j*3+1)=255;
*(Buffer+j*3+2)=255;
}
else{
*(Buffer+j*3) = (m_pmap.mdata[i][j]*50)%255;
*(Buffer+j*3+1)=255-((m_pmap.mdata[i][j]*50)%255);
*(Buffer+j*3+2)=155+(m_pmap.mdata[i][j]*50)%100;
}
}
}
fwrite(&bitmapFileHeader,1,sizeof(BITMAPFILEHEADER),filePtr);
fwrite(&bitmapInfoHeader,1,sizeof(BITMAPINFOHEADER),filePtr);
fwrite(imageData,1,bitmapInfoHeader.biSizeImage,filePtr);
fclose(filePtr);
delete[] imageData;
}