35 fopen_s( &file, filename,
"r" );
38 return auxDIBImageLoad( filename );
52 std::ifstream file( filename.c_str(), ios::binary );
57 file.read( (
char *)begin,
sizeof(begin) );
64 if( begin[0] ==
'B' && begin[1] ==
'M' ) {
65 bool ret = ReadDIBFile( file );
74 #define DIB_HEADER_MARKER ((WORD) ('M' << 8) | 'B')
89 bool TextureLoaderBMP::ReadDIBFile( istream &file ) {
90 BITMAPFILEHEADER bmfHeader;
92 BITMAPINFOHEADER * pBMI;
95 file.read( (
char *)&bmfHeader,
sizeof(bmfHeader) );
105 nBMISize = bmfHeader.bfOffBits -
sizeof(bmfHeader);
106 pBMI = (BITMAPINFOHEADER *)(
new BYTE[nBMISize]);
107 file.read( (
char *)pBMI, nBMISize );
114 if( pBMI->biHeight < 0 || pBMI->biWidth < 0 || pBMI->biCompression != BI_RGB ) {
120 setHeight( pBMI->biHeight );
121 setWidth( pBMI->biWidth );
124 RGBQUAD *bmiColors = (RGBQUAD *)(((BYTE *)pBMI) + pBMI->biSize);
132 BYTE *rowbuf =
new BYTE[usewidth4];
140 BYTE *image =
new BYTE[usewidth * getHeight()];
142 pimage =
new BYTE *[getHeight()];
143 for(
unsigned int i=0;i<getHeight();i++, image += usewidth )
146 switch( pBMI->biBitCount ) {
152 for(
unsigned int r=0;r < getHeight();r++ ) {
153 file.read((
char *)rowbuf, usewidth1);
160 BYTE *row = pimage[r];
161 for(
unsigned int c=0;c < getWidth();c++ ) {
162 *row++ = bmiColors[*img].rgbBlue;
163 *row++ = bmiColors[*img].rgbGreen;
164 *row++ = bmiColors[*img++].rgbRed;
170 for(
unsigned int r=0; r < getHeight(); r++ ) {
171 file.read( (
char *)rowbuf, usewidth3 );
178 BYTE *row = pimage[r];
179 for(
unsigned int c=0;c < getWidth()*3;c++ ) {
186 for(
unsigned int r=0; r < getHeight(); r++ ) {
187 file.read( (
char *)rowbuf, usewidth4 );
194 BYTE *row = pimage[r];
195 for(
unsigned int c=0;c<getWidth();c++ ) {
225 setFormat( GL_BGR_EXT );