Browse Source

engine: common: imagelib: fixed loading BMP files with v4/v5 headers

pull/2/head
SNMetamorph 3 years ago committed by a1batross
parent
commit
cd2720ba81
  1. 11
      engine/common/imagelib/img_bmp.c
  2. 1
      engine/common/imagelib/img_bmp.h

11
engine/common/imagelib/img_bmp.c

@ -41,7 +41,7 @@ qboolean Image_LoadBMP( const char *name, const byte *buffer, fs_offset_t filesi
buf_p = (byte *)buffer; buf_p = (byte *)buffer;
memcpy( &bhdr, buf_p, sizeof( bmp_t )); memcpy( &bhdr, buf_p, sizeof( bmp_t ));
buf_p += sizeof( bmp_t ); buf_p += BI_FILE_HEADER_SIZE + bhdr.bitmapHeaderSize;
// bogus file header check // bogus file header check
if( bhdr.reserved0 != 0 ) return false; if( bhdr.reserved0 != 0 ) return false;
@ -53,9 +53,9 @@ qboolean Image_LoadBMP( const char *name, const byte *buffer, fs_offset_t filesi
return false; return false;
} }
if( bhdr.bitmapHeaderSize != 0x28 ) if(!( bhdr.bitmapHeaderSize == 40 || bhdr.bitmapHeaderSize == 108 || bhdr.bitmapHeaderSize == 124 ))
{ {
Con_DPrintf( S_ERROR "Image_LoadBMP: invalid header size %i\n", bhdr.bitmapHeaderSize ); Con_DPrintf( S_ERROR "Image_LoadBMP: %s have non-standard header size %i\n", name, bhdr.bitmapHeaderSize );
return false; return false;
} }
@ -187,6 +187,7 @@ qboolean Image_LoadBMP( const char *name, const byte *buffer, fs_offset_t filesi
return false; return false;
} }
image.depth = 1;
image.size = image.width * image.height * bpp; image.size = image.width * image.height * bpp;
image.rgba = Mem_Malloc( host.imagepool, image.size ); image.rgba = Mem_Malloc( host.imagepool, image.size );
@ -313,8 +314,8 @@ qboolean Image_LoadBMP( const char *name, const byte *buffer, fs_offset_t filesi
} }
VectorDivide( reflectivity, ( image.width * image.height ), image.fogParams ); VectorDivide( reflectivity, ( image.width * image.height ), image.fogParams );
if( image.palette ) Image_GetPaletteBMP( image.palette ); if( image.palette )
image.depth = 1; Image_GetPaletteBMP( image.palette );
return true; return true;
} }

1
engine/common/imagelib/img_bmp.h

@ -22,6 +22,7 @@ GNU General Public License for more details.
======================================================================== ========================================================================
*/ */
#define BI_FILE_HEADER_SIZE 14
#define BI_SIZE 40 // size of bitmap info header. #define BI_SIZE 40 // size of bitmap info header.
#if !defined(BI_RGB) #if !defined(BI_RGB)
#define BI_RGB 0 // uncompressed RGB bitmap(defined in wingdi.h) #define BI_RGB 0 // uncompressed RGB bitmap(defined in wingdi.h)

Loading…
Cancel
Save