Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Composants | Déclarations

pi2d14_imagebmp.cpp

Aller à la documentation de ce fichier.
00001 // ImageBMP.cpp: implementation of the ImageBMP class.
00002 //
00004 
00005 #include <pi2d14/pi2d14_imagebmp.h>
00006 
00008 // Construction/Destruction
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)   //on continue seulement si le fichier existe
00032         {
00033                 //lecture de l'en-tete
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                 //en commentaire ==> ce qui ne marche pas ici
00040                 // faisait planter le chargement
00041 /*              if (bmph.bfOffBits==794)
00042                 {
00043                         fread(&bmph.biSize,1,4,f);
00044                         fread(&bmph.biWidth,1,2,f);
00045                         fread(&bmph.biHeigth,1,2,f);
00046                         fread(&bmph.biPlanes,1,2,f);
00047                         fread(&bmph.biBitCount,1,2,f);
00048                 };*/
00049 //              if (bmph.bfOffBits==1078)
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;       //pour mettre a true, le fichier doit existe et l'image doit etre en 24bits
00067 
00068                         delete []datas;
00069                         datas = new unsigned char[(unsigned int)bmph.biWidth*(unsigned int)bmph.biHeigth*3];
00070 
00071                         //chargement des donnees au format du fichier : BGR
00072                         fread(&datas[0], sizeof(unsigned char), (unsigned int)bmph.biWidth*(unsigned int)bmph.biHeigth*3, f);
00073 
00074                         //mise a jour des donnees au format RGB par echange des composantes R et B
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 }

Généré le Fri Mar 26 13:02:03 2004 pour AlgoAtomD par doxygen 1.3.5