00001
00002
00004
00005 #include <pi2d14/pi2d14_imagebmp.h>
00006
00008
00010
00011 GRAPHICSTOOLS::ImageBMP::ImageBMP()
00012 {
00013 datas = new unsigned char[3];
00014 bmph.biWidth=1;
00015 bmph.biHeigth=1;
00016 bmph.biBitCount=24;
00017 }
00018
00019 GRAPHICSTOOLS::ImageBMP::~ImageBMP()
00020 {
00021 delete [] datas;
00022 }
00023
00024 bool GRAPHICSTOOLS::ImageBMP::load(char *filepath)
00025 {
00026 bool ret=false;
00027 FILE *f=0;
00028
00029 f=fopen(filepath,"rb");
00030
00031 if(f)
00032 {
00033
00034 fread(&bmph.bfType,1,sizeof(unsigned short),f);
00035 fread(&bmph.bfSize,1,sizeof(unsigned int),f);
00036 fread(&bmph.bfReserved1,1,sizeof(unsigned short),f);
00037 fread(&bmph.bfReserved2,1,sizeof(unsigned short),f);
00038 fread(&bmph.bfOffBits,1,sizeof(unsigned int),f);
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 fread(&bmph.biSize,1,sizeof(unsigned int),f);
00052 fread(&bmph.biWidth,1,sizeof(unsigned int),f);
00053 fread(&bmph.biHeigth,1,sizeof(unsigned int),f);
00054 fread(&bmph.biPlanes,1,sizeof(unsigned short),f);
00055 fread(&bmph.biBitCount,1,sizeof(unsigned short),f);
00056 fread(&bmph.biCompression,1,sizeof(unsigned int),f);
00057 fread(&bmph.biSizeImage,1,sizeof(unsigned int),f);
00058 fread(&bmph.biXPelsPerMeter,1,sizeof(unsigned int),f);
00059 fread(&bmph.biYPelsPerMeter,1,sizeof(unsigned int),f);
00060 fread(&bmph.biClrUsed,1,sizeof(unsigned int),f);
00061 fread(&bmph.biClrImportant,1,sizeof(unsigned int),f);
00062
00063
00064 if(bmph.biBitCount==24)
00065 {
00066 ret=true;
00067
00068 delete []datas;
00069 datas = new unsigned char[(unsigned int)bmph.biWidth*(unsigned int)bmph.biHeigth*3];
00070
00071
00072 fread(&datas[0], sizeof(unsigned char), (unsigned int)bmph.biWidth*(unsigned int)bmph.biHeigth*3, f);
00073
00074
00075 unsigned char tmp;
00076 for(unsigned int i=0;i<(unsigned int)bmph.biWidth*(unsigned int)bmph.biHeigth*3;i+=3)
00077 {
00078 tmp=datas[i];
00079 datas[i]=datas[i+2];
00080 datas[i+2]=tmp;
00081 }
00082 }
00083
00084 fclose(f);
00085 }
00086
00087 return ret;
00088 }
00089
00090 long GRAPHICSTOOLS::ImageBMP::getWidth()
00091 {
00092 return bmph.biWidth;
00093 }
00094
00095 long GRAPHICSTOOLS::ImageBMP::getHeight()
00096 {
00097 return bmph.biHeigth;
00098 }
00099
00100 unsigned short GRAPHICSTOOLS::ImageBMP::getBPP()
00101 {
00102 return bmph.biBitCount;
00103 }
00104
00105 unsigned char* GRAPHICSTOOLS::ImageBMP::getDatasPointer()
00106 {
00107 return &datas[0];
00108 }