From cd2720ba81c765ea06f31f0b7efef37625950080 Mon Sep 17 00:00:00 2001 From: SNMetamorph <25657591+SNMetamorph@users.noreply.github.com> Date: Sat, 12 Mar 2022 22:59:38 +0400 Subject: [PATCH] engine: common: imagelib: fixed loading BMP files with v4/v5 headers --- engine/common/imagelib/img_bmp.c | 11 ++++++----- engine/common/imagelib/img_bmp.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/engine/common/imagelib/img_bmp.c b/engine/common/imagelib/img_bmp.c index 74583716..c81c3701 100644 --- a/engine/common/imagelib/img_bmp.c +++ b/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; memcpy( &bhdr, buf_p, sizeof( bmp_t )); - buf_p += sizeof( bmp_t ); + buf_p += BI_FILE_HEADER_SIZE + bhdr.bitmapHeaderSize; // bogus file header check 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; } - 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; } @@ -187,6 +187,7 @@ qboolean Image_LoadBMP( const char *name, const byte *buffer, fs_offset_t filesi return false; } + image.depth = 1; image.size = image.width * image.height * bpp; 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 ); - if( image.palette ) Image_GetPaletteBMP( image.palette ); - image.depth = 1; + if( image.palette ) + Image_GetPaletteBMP( image.palette ); return true; } diff --git a/engine/common/imagelib/img_bmp.h b/engine/common/imagelib/img_bmp.h index 72b4d8a2..a5728eeb 100644 --- a/engine/common/imagelib/img_bmp.h +++ b/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. #if !defined(BI_RGB) #define BI_RGB 0 // uncompressed RGB bitmap(defined in wingdi.h)